JAVA模拟题:TestoftheJavaSkill(1)

文章作者 100test 发表时间 2007:03:14 17:03:29
来源 100Test.Com百考试题网


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

相关文章


Java认证模考试题(一)
64位环境中的Java(下)
64位环境中的Java(上)
JAVA教程:解析Java的多线程机制
JAVA模拟题:TestoftheJavaSkill(1)
JavaSE6.0桌面API编程 (中)
JAVA基础:利用Java实现zip压缩解压缩
JavaSE6.0桌面API编程 (上)
JAVA模拟题:TestoftheJavaSkill(3)
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛