Problem

Show the output of the following program:public class Test {public static void main(String...

Show the output of the following program:

public class Test {

public static void main(String[] args) {

Circle circle1 = new Circle(1);

Circle circle2 = new Circle(2);

swap1(circle1, circle2);

System.out.println("After swap1: circle1 = " +

circle1.radius + " circle2 = " + circle2.radius);

swap2(circle1, circle2);

System.out.println("After swap2: circle1 = " +

circle1.radius + " circle2 = " + circle2.radius);

}

public static void swap1(Circle x, Circle y) {

Circle temp = x;

x = y;

y = temp;

}

public static void swap2(Circle x, Circle y) {

double temp = x.radius;

x.radius = y.radius;

y.radius = temp;

}

}

class Circle {

double radius;

Circle(double newRadius) {

radius = newRadius;

}

}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT