给出以下代码,请问该程序的运行结果是什么?1. public abstract class Example{2. public abstract void mth1();3. public static void mth2(){4. int mth2 = 30;5. System.out.printIn(“mth2=”+mth2);6. }7. public abstract void mth3();8. }
A. 程序编译通过。
B. 第1行发生编译错误。
C. 第3行发生编译错误。
D. 第7行发生编译错误。
查看答案
给出以下代码,请问该程序的运行结果是什么?class Base{Base(){System.out.printIn(“Message 1:In the base class constructor”);}}abstract class Sub1 extends Base{Sub 1(){System.out.printIn(“Message 2:In the abstract class SubI’s constructor”);}}class Sub2 extends Sub1{public Sub2(){System.out.printIn(“Message 3:In the Sub2 class’s constructor”);}public static void main(String args[]){Sub2 d2 = new Sub2();}}
A. 代码编译失败,因为非抽象类不能被扩展为抽象类。
B. 代码编译失败,因为抽象类不能有构造器。
C. 打印输出Message 1:In the base class constructorMessage 3:In the derived2 class\’s constructor.
D. 打印输出Message 1:In the base class constructorMassage 2:In the abstract class Derived1\’s constructorMessage 3:In the derived2 class\’s constructor.
给出以下代码,请问该程序的运行结果是什么?1. public class Example{2. static int x;3. static public void main(String[]args){4. x=x+1;5. System.out.println(“Value is”+x);6. }7. }
A. 代码编译失败,因为变量x未被初始化。
B. 代码编译成功,打印输出Value is 1。
C. 代码编译成功,但在运行期第5行抛出一个NullPointerException异常。
D. 代码编译失败,因为main()方法形式不对。
给出以下代码,请问该程序的运行结果是什么?class Example{int x;String s;float fl;boolean []b =new boolean [5];public static void main(String[]args){System.out.println(x);System.out.println(s);System.out.println(fl);System.out.println{b[2]};}}
A. 打印输出0 null 0.0 false
B. 打印输出 0 ﹟﹟ 0.0 True
C. 代码编译失败,因为布尔型数组声明的不明确。
D. 代码编译失败,因为静态方法不能访问非静态类成员。
给出以下代码,请问该程序的运行结果是什么?1. class Example{2. static String s;3. public static void main(String[]args){4. int x =4;5. if(x <4)6. System.out.printIn(“Val=”+x);7. else8. System.out.printIn(s);9. }10.}
A. 打印输出Val=null
B. 打印输出Val=
C. 打印输出null
D. 打印输出空白行