black

Java认证考试综合练习

登录

单项选择题

1. class Alpha { void m1() {} }  
2. class Beta extends Alpha { void m2() { } }  
3. class Gamma extends Beta { }  
4.  
5. class GreekTest {  
6. public static void main(String [] args) {  
7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() };  
8. for(Alpha a2 : a) {  
9. a2.m1();  
10. if (a2 instanceof Beta || a2 instanceof Gamma)  
11. //insert code here  
12. }  
13. }  
14. }  
哪一行代码插入到第11行,将编译但是会在运行时产生异常?()  

A. a2.m2();
B. ((Beta)a2).m2();
C. ((Alpha)a2).m2();
D. ((Gamma)a2).m2();

相关考题

单项选择题 程序:   class MyDate{   private int year;   private int month;   private int day;   public MyDate( int year, int month,int day){   this.year=year;   this.month=month;   this.day=day;  }   //Override Method  }   为了让new MyDate(1980,11,9)==(判断是否相等)new MyDate(1980,11,9) 返 回true,必须在Override Method处覆盖哪个方法?()

单项选择题 class TestReference{   public static void main(String[] args){   int x=2;   TestReference tr = new TestReference();   System.out.print(x);   tr.change(x);   System.out.print(x);  }   public void change(int num){   num = num + 1;  }  }   程序运行后的输出是哪项()?

单项选择题 class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()

All Rights Reserved 版权所有©求知题库网库(csqiuzhi.com)

备案号:湘ICP备14005140号-1

经营许可证号:湘B2-20140064