venerdì 29 marzo 2013

Q85


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 ofclass x

B.
addingthe protected modifier to the x() constructor

C.
changingthe 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

 

Risposta C. Infatti con il modificatore privato il metodo non è visibile dentro two.

 

Nessun commento:

Posta un commento