Given a java source file:
class x {
x () {}
private void one () {}
}
public class Y extends x {
Y () {}
private void two () {one();}
public static void main (string [] args) {
new Y().two ();
}
}
What changes will make this code compile?
A.
adding the public modifier to the declaration of class x
B.
adding the protected modifier to the x() constructor
C.
changing the private modifier on the declaration of the one() method to protected
D.
removing the Y () constructor
E.
removing the private modifier from the two () method
Explanation:
Using the private protected, instead of the private modifier, for the declaration of the
one() method, would enable the two() method to access the one() method.
cf. https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
The correct answer is C
Answer: C
Explanation:
A, B, D are wrong because method one() is inaccessible for class Y in all cases.