Saturday, 4 February 2012

Question 127 : Modifiers

Given:
10. class Foo {
11. private int x;
12. public Foo (int x ) { this.x = x; }
13. public void setX( int X ) { this.x = x; }
14. public int getX() { return x; }
15. }
16. 
17. public class Gamma {
18. 
19. static Foo fooBar( Foo foo ) { 
20. foo = new Foo( 100 );
21. return foo;
22. { 
23. 
24. public static void main ( String[] args ) {
25. Foo foo = new Foo ( 300 );
26. System.out.print( foo.getX() + "-" );
27.
28. Foo fooFoo = fooBar( foo );
29. System.out.print( foo.getX() + "-" );
30. Sustem.out.print( fooFoo.getX() + "-" );
31. 
32. foo = fooBar( fooFoo );
33. System.out.print( foo.getX() + "-" );
34. System.out.print( fooFoo.getX() );
35. }
36. }
What is the result?

A. 300-100-100-100-100
B. 300-300-100-100-100
C. 300-300-300-100-100
D. 300-300-300-300-100

No comments:

Post a Comment