阅读下列代码段 class TestimplementsRunnable{ publicintrun(){ inti=0; while(true){ i++; System.out.println("i="+1);

admin2010-03-15  15

问题 阅读下列代码段    class TestimplementsRunnable{    publicintrun(){    inti=0;    while(true){    i++;    System.out.println("i="+1);    }    }    }    上述代码的编译结果是(    )。

选项 A、程序通过编译并且run()方法可以正常输出递增的i值
B、程序通过编译,调用run()方法将不显示任何输出
C、程序不能通过编译,因为while的循环控制条件不能为“true”
D、程序不能通过编译,因为run()方法的返向值类型不是void

答案D

解析 while的循环控制条件可以为“true”,run方法没有返回值,所以不能是int型,故此程序不能通过编译。
转载请注明原文地址:https://kaotiyun.com/show/Un9p777K
0

最新回复(0)