Consider the aggregated Circle class and the Point class pub
Solution
a Ans) Below is the statement that will create the new \'Circle\' object:-
Circle c=new Circle(new Point(3,4) , 4);
b Ans) Below is the given implementation of Circle class showing where shallow references are used
public class Circle {
private Point center;
private int radius;
public Circle(Point c, int r) {
center = c; // this line the shallow copy
radius = r;
}
public Point getCenter() {
return center; // this line the shallow return
}
}
Below is the modified Circle class using deep references
public class Circle {
private Point center;
private int radius;
public Circle(Point c, int r) {
center = new Point(c.getX , c.getY); // this line the deep copy
radius = r;
}
public Point getCenter() {
return new Point(center.getX , center.getY); // this line the deep return
}
}
