Limited access

Upgrade to access all content for this subject

Consider the following Distance class.

double myDistance=0;

public Distance(int myDistance) 
{
           this.myDistance=myDistance;
}

public Distance increase(int amount)
{
           myDistance+=amount;
           return this;
}

public Distance decrease(int amount)
{
           myDistance-=amount;
           return this;
}

public String toString()
{
           return "The distance is: " + Double.toString(myDistance);
}

Consider the following code in the main program.

    Distance dist1 = new Distance(50);
    Distance dist2=dist1.decrease(100);
    Distance dist3=dist2.increase(200);
    System.out.println(dist1);

What is printed as a result of executing the code?

A

The distance is: 150

B

The distance is: 50

C

The distance is: -50

D

The distance is: -100

E

null

Select an assignment template