What changes will make this code compile?

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?

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.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Kurt

Kurt

The correct answer is C

imyrta

imyrta

Answer: C

Explanation:

A, B, D are wrong because method one() is inaccessible for class Y in all cases.