Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1503938
  • 博文数量: 3500
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 43870
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 20:31
文章分类

全部博文(3500)

文章存档

2008年(3500)

我的朋友

分类:

2008-05-04 20:49:22

一起学习
Question 1: What will happen when you attempt to compile and run this code? class Base{ public final void amethod(){ System.out.println(“amethod”); } } public class Fin extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); } } A. Compile time error indicating that a class with any final methods must be declared final itself B. Compile time error indicating that you cannot inherit from a class with final methods C. Run time error indicating that Base is not defined as final D. Success in compilation and output of “amethod” at run time Question 2: Given the following code what will be output? public class Pass{ static int j = 20; public static void main(String argv[]){ int i=10; Pass p = new Pass(); p.amethod(i); System.out.println(i); System.out.println(j); } public void amethod(int x){ x=x*2; j=j*2; } } A. Error: amethod parameter does not match variable B. 20 and 40 C. 10 and 40 D. 10 and 20 Question 3: What happens when you attempt to compile and run these two files in the same directory? // File P1.java package MyPackage; class P1{ void afancymethod(){ System.out.println(“what a fancy method”); } } // File P2.java public class P2 extends P1{ afancymethod(); } A. Both compile and P2 outputs “what a fancy method” when run B. Neither will compile C. Both compile but P2 has an error at run time D. P1 compiles cleanly but P2 has an error at compile time Question 4: Which statement declares a variable a which is suitable for referring to an array of 50 string objects? A. char a[][]; B. String a[]; C. String []a; D. Object a[50]; E. String a[50]; Question 5: Given the following declaration String s = "Example"; Which are legal code? A. s >>> = 3; B. s >> = 2; C. int i = s.length(); D. String t = "For " s; E. s = s 10; Question 6: What will happen when you compile and run the following code? public class Scope{ private int i; public static void main(String argv[]){ Scope s = new Scope(); s.amethod(); } public static void amethod(){ System.out.println(i); } } A. A value of 0 will be printed out B. Nothing will be printed out C. A compile time error D. A compile time error complaining of the scope of the variable i Question 7: What will happen when you attempt to compile and run this program? public class Outer{ public String name = “Outer”; public static void main(String argv[]){ Inner i = new Inner(); i.showName(); }//End of main private class Inner{ String name = new String(“Inner”); void showName(){ System.out.println(name); } }//End of Inner class } A. Compile and run with output of “Outer” B. Compile and run with output of “Inner” C. Compile time error because Inner is declared as private D. Compile time error because of the line creating the instance of Inner Question 8: What will be the result when you attempt to compile and run the following code? public class Conv{ public static void main(String argv[]){ Conv c = new Conv(); String s = new String(“ello”); c.amethod(s); } public void amethod(String s){ char c = ‘H’; c =s; System.out.println(c); } } A. Compilation and output the String “Hello” B. Compilation and output the String “ello” C. Compilation and output the String “elloH” D. Compile time error Question 9: What code placed after the comment: // Start For loop would populate the elements of the array ia[] with values of the variables i ? public class Lin{ public static void main(String argv[]){ Lin l = new Lin(); l.amethod(); } public void amethod(){ int ia[] = new int[4]; // Start For loop { ia[i] = i; System.out.println(ia[i]); } } } A. for(int i=0; i 下载本文示例代码


Test of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java SkillTest of the Java Skill
阅读(166) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~