Question: Look at following Java code ----------------------------------------------------------------------------------------------- class point implements Cloneable { int x; int y; public point(int x, int y) { this.x = x; this.y

Look at following Java code

----------------------------------------------------------------------------------------------- class point implements Cloneable {

int x; int y;

public point(int x, int y) { this.x = x; this.y = y; }

@Override protected Object clone() throws CloneNotSupportedException { return super.clone();

} }

class Circle implements Cloneable {

point center; int radius;

public Circle(point center, int radius) { this.center = center; this.radius = radius; }

@Override protected Object clone() throws CloneNotSupportedException { Circle clone = (Circle) super.clone(); return clone;

} }

public class JavaApplication6 {

public static void main(String[] args) { Circle c1 = new Circle(new point(10, 20), 10), c2 = null; try { c2 = (Circle) c1.clone(); } catch (CloneNotSupportedException ex) { System.out.println("Clone failed"); } System.out.println(c1 == c2); System.out.println(c1.center == c2.center); }

}

-----------------------------------------------------------------------------------------------------

If you think that this code does not give you a clone, change the code to get a clone

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!