单项选择题
public class TestApp{
public static void main(String[] args){
try{
String myname = null;
if(myname.length()>2)
System.out.print(“1”);
}catch(NullPointerException e){
System.out.print(“2”); } } }
上述程序运行后的输出是哪项?()
A. 1
B. 12
C. 21
D. 2
点击查看答案&解析
相关考题
-
单项选择题
现有: 1. class Book { 2. private final void read() { System.out.print("book "); } 3. } 4. class Page extends Book { 5. public static void main(String [] args) { 6. // insert code here 7. } 8. private final void read() { System.out.print("page "); } 9. } 和如下三个代码片段( x, y, z ): x. // just a comment y. new Page().read(); z. new Book().read(); 分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()
A. 0
B. 1
C. 2
D. 3 -
单项选择题
1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat implements Feline { 8. public void eat() { } 9. } 和以下三个接口声明: interface Feline extends Animal { } interface Feline extends Animal { void eat(); } interface Feline extends Animal { void eat() { } } 分别插入到第 5 行,有多少行可以编译?()
A.0
B.1
C.2
D.3 -
单项选择题
class TestMain { static int x = 2; static { x = 4; } static public void main(String[] args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()
A. 3
B. 5
C. 编译失败
D. 运行时异常被抛出
