|
8:Which of the following statements are not legal? A.long l = 4990; B.int i = 4L; C.double d = 34.4; D.double t = 0.9F. 9: Give the following java class: public class Example{ public static void main(String args[]){ static int x[] = new int[15]; System.out.println(x[5]); } } Which statement is corrected? Give the following java class: public class Example{ public static void main(String args[]){ static int x[] = new int[15]; System.out.println(x[5]); } } Which statement is corrected? A.When compile, some error will occur. B.When run, some error will occur. C.Output is zero. D.Output is null. 10:下面关于变量及其范围的陈述哪些是错的。 A.实例变量是类的成员变量。 B.实例变量用关键字static声明。 C.在方法中定义的局部变量在该方法被执行时创建 D.局部变量在使用前必须被初始化。 11: public class X{ public Object m(){ Object o = new Float(3.14F);//line 3 Object [] oa = new Object[1];//line 4 oa[0] = o;//line 5 o=null;//line 6 return oa[0];//line 7 } } When is the Float object, created in line 3,eligible for garbage collection? public class X{ public Object m(){ Object o = new Float(3.14F);//line 3 Object [] oa = new Object[1];//line 4 oa[0] = o;//line 5 o=null;//line 6 return oa[0];//line 7 } } When is the Float object, created in line 3,eligible for garbage collection? A.just after line 5. B.just after line 6 C.just after line 7(that is,as the method returns) D.never in this method 12: Which is the most appropriate code snippet that can be inserted at line 18 in the following code? (Assume that the code is compiled and run with assertions enabled) 1. import java.util.*; 2. 3. public class AssertTest 4. { 5. private HashMap cctld; 6. 7. public AssertTest() 8. { 9. cctld = new HashMap(); 10. cctld.put("in", "India"); 11. cctld.put("uk", "United Kingdom"); 12. cctld.put("au", "Australia"); 13. // more code... 14. } 15. // other methods .... 16. public String getCountry(String countryCode) 17. { 18. // What should be inserted here? 19. String country = (String)cctld.get(countryCode); 20. return country; 21. } 22. } Which is the most appropriate code snippet that can be inserted at line 18 in the following code? (Assume that the code is compiled and run with assertions enabled) 1. import java.util.*; 2. 3. public class AssertTest 4. { 5. private HashMap cctld; 6. 7. public AssertTest() 8. { 9. cctld = new HashMap(); 10. cctld.put("in", "India"); 11. cctld.put("uk", "United Kingdom"); 12. cctld.put("au", "Australia"); 13. // more code... 14. } 15. // other methods .... 16. public String getCountry(String countryCode) 17. { 18. // What should be inserted here? 19. String country = (String)cctld.get(countryCode); 20. return country; 21. } 22. } A.assert countryCode != null; B.assert countryCode != null : "Country code can not be null" ; C.assert cctld != null : "No country code data is available"; D.assert cctld : "No country code data is available"; 13: Give the following code: public class Example{ public static void main(String args[] ){ int l=0; do{ System.out.println(“Doing it for l is:”+l); }while(--l>0) System.out.println(“Finish”); } } Which well be output: Give the following code: public class Example{ (责任编辑:职场达人) |


