자격증/OCJP_ExamB

QUESTION 35

IT grow. 2018. 7. 10. 22:49
반응형

QUESTION 35 


Which three code fragments, added individually at line 29, produce the output 100? (Choose three.) 

 

 

10. class Inner { 

11.     private int x; 

12.     public void setX( int x ){ this.x = x; } 

13.     public int getX(){ return x;} 

14. } 

15.  

16. class Outer { 

17.     private Inner y; 

18.     public void setY( Inner y ){ this.y = y; } 

19.     public Inner getY() { return y; } 

20. } 

21.  

22. public class Gamma { 

23.     public static void main(String[] args) { 

24.         Outer o = new Outer(); 

25.         Inner i = new Inner(); 

26.         int n = 10; 

27.         i.setX(n); 

28.         o.setY(i); 

29.         // insert code here 29 

30.         System.out.println(o.getY().getX()); 

31.          

32.     } 

33. } 

 

A. n = 100; 

B. i.setX( 100 ); 

C. o.getY().setX( 100 ); 

D. i = new Inner(); i.setX( 100 ); 

E. o.setY( i ); i = new Inner(); i.setX( 100 ); 

F. i = new Inner(); i.setX( 100 ); o.setY( i ); 

 


Solution : BCF 

 


plus imformation 


A. 10 

 

B. 100 

 

C. 100 

 

D. 10 

 

E. 10 

 

F. 100



반응형