public class Point { private int x, y; int getX() {return x;} public int getY() {return y;} public Point(int x0, int y0){ x = x0; y = y0; } }
1、次のクラスの中にアクセス制限に違反しているメソッドは存在しますか?
package question; import exercise.Point;
public class Q1{ static void main(String[] args){ Point p = new Point(3, 4); System.out.println(p.getX()); System.out.println(p.getY()); } }
2、下のmoveXメソッドの定義はアクセス制限に違反しているか?
package execise;
class Point3D extends Point { private int z; int getZ() {return z;} void moveX(int dx){ x += dx;} Point3D(int x0, int y0){ super(x0, y0); } }
3、下のクラス定義の中で、アクセス制限に違反しているメソッドの定義は?
package question; import exercise.Point;
public class ColorPoint extends Point{ private String color; public String getColor() {return color;} public int xpos() {return getX(); } public int ypos() {return getY(); } public ColorPoint(int x0, int y0, String c) { super(x0, y0); color = c; } }