当编译并运行下列程序段时,将会发生什么情况?()class VarInBase{int i=10;public void print(){System.out.println("i="+i);}}class VarInSub extends VarInBase{int i=100;public void print(){int i=1000;System.out.println("i="+i);}}public class Main{public static void main(String args[]){VarInBase m=new VarInSub();m.print();}}
A. 输出i=10;
B. 输出i=100;
C. 输出i=1000;
D. 编译错误;
()是指子类中的一个方法与父类中的方法有相同的方法名并具有相同参数和类型的参数列表。
A. 重载方法;
B. 覆盖方法;
C. 强制类型转换;
D. 以上都不对;
以下哪些代码块能够编译通过?()
A. class Fruit { }public class Orange extends Fruit {public static void main(String[]args){Fruit f=new Fruit();Orange o=f;}};
B. class Fruit {}public class Orange extends Fruit {public static void main(String[]args){Orange o=new Orange();Fruit f=o;}};
C. interface Fruit {}public class Apple implements Fruit {public static void main(String[]args){Fruit f=new Fruit();Apple a=f;}};
D. interface Fruit {}public class Apple implements Fruit {public static void main(String []args){Apple a=new Apple();Fruit f=a;}};
E. interface Fruit {}class Apple implements Fruit {}class Orange implements Fruit {}public class MyFruit {public static void main(String []args){Orange o=new Orange();Fruit f=o;Apple a=f;}}
下面哪些是合法的语句(以下Panel、Applet和Frame类来自于java.awt包,请查阅相关的JavaDoc文档来了解它们是否有继承关系)?()
A. Object o = new String("abcd");
Boolean b = true;
C. Panel p = new Frame();
D. Applet a = new Panel();
E. Panel p = new Applet();