4、.What will be printed when you execute the following code? 2. 3.class X 4.{ 5. Y b = new Y(); 6. X() 7. { 8. System.out.print("X"); 9. } 10.} 11. 12.class Y 13.{ 14. Y() 15. { 16. System.out.print("Y"); 17. } 18.}
5、19. 20.public class Z extends X 21.{ 22. Y y = new Y(); 23. Z() 24. { 25. System.out.print("Z"); 26. } 27. public static void main(String[] args) 28. { 29. new Z(); 30. } 31.} 32. 33.Choices: Whatwillbeprintedwh
6、enyouexecutethefollowingcode?classX{Yb=newY();X(){System.out.print("X");}}classY{Y(){System.out.print("Y");}}publicclassZextendsX{Yy=newY();Z(){System.out.print("Z");}publicstaticvoidmain(String[]args){newZ();}}Choices:A.ZB.YZC.XYZD.YXYZ6:c1.Give the followin
7、g method: 2. public void method( ){ 3. String a,b; 4. a=new String(“hello world”); 5. b=new String(“game over”); 6. System.out.println(a+b+”ok”); 7. a=null; 8. a=b; 9. System.out.println(a); 10. } 11.In the absence of compiler optimization, which i
8、s the earliest point the object a refered is definitely elibile to be garbage collection. Givethefollowingmethod:publicvoidmethod(){Stringa,b;a=newString(“helloworld”);b=newString(“gameo