题目内容

给出以下代码,请问该程序的运行结果是什么?class Example{public static void main(String []args){C c=newC();c.e();}}class P{final void methodP(){…}}class C extends P{void e(){methodP();}}

A. 代码编译错误,因为P类不是final类。
B. 代码编译错误,因为子类C不能调用父类P中的final方法methodP()。
C. 代码编译成功。
D. 代码编译成功,但运行时会抛出NoSMuchethodException异常。

查看答案
更多问题

给出以下代码,请问该程序的运行结果是什么?public class Example{final int x;public Example(){System.out.println(x + 10);}public static void main(String args[]){Example ex = new Example();}}

A. 代码编译错误。
B. 运行期异常。
C. 打印输出10
D. 打印输出0

给出以下代码,请问该程序的运行结果是什么?Class Base{String str;public Base(){}public Base(String s){str = s;}}public class Sub extend Base{public static void main(String args[]){final Base b = new Base(”Hello”);b = new Base(”How are you”)b.str = “How is going”;System.out.printIn(“Greeting is:”+b.str);}}

A. 代码编译错误。
B. 运行期异常。
C. 打印输出Hello
D. 打印输出How is going

给出以下代码,请问该程序的运行结果是什么?public abstract class AbstractClass{public AbstractClass(){System.out.printIn("this is an abstract class constructor!”);}public void aMethod(){System.out.printIn(“This is in the method in the abstract class”);}}

A. 代码编译失败,因为抽象类不能有构造器。
B. 代码编译失败,因为抽象类的方法不能有返回值类型声明。
C. 代码编译失败,因为当类不存在抽象方法时,是不能定义为抽象类的。
D. 代码编译成功,并且因为该类实际上不是抽象类,因此可以被实例化。
E. 代码编译成功,但不能被实例化。可以被扩展为非抽象类,子类的构造 器可以调用抽象父类的构造器。
F. 代码编译成功,但不能被实例化。可以被扩展为非抽象类,子类的构造器不可以调用抽象父类的构造器。

给出以下代码,请问该程序的运行结果是什么?public class CloseWindow extendsFrame implements WindowListener{public CloseWindow(){addWindowListener(this);setSize(300,300);setVisible(true);}public void windowClosing(WindowEvent e){System.exit(0);}public static viod main(String args[]){CloseWindowCW = new CloseWindow();}}

A. 代码编译失败。
B. 运行期异常。
C. 运行正常。

答案查题题库