Java
public class Point { protected int x; protected int y; public Point (int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } } |
THE FOLLOWING 3 QUESTIONS REFER TO THE CODE FRAGMENT ABOVE
Explain: ___________________________________________
Explain: ___________________________________________
1. Answer: False
Point class is not immutable because the class is not declared as final. Data members must be declared as final.
2. Answer: True
Subclasses of Point class have direct access to the X and Y because X and Y are declared as protected data members. Protected data members are accessible inside a package or sub classes in different packages.
3. Answer: True
Every class in java is a subclass of an object class. Point class is also a subclass of the Object class and it does not implement any interfaces.
Get Answers For Free
Most questions answered within 1 hours.