更多"[单选题]下列代码编译或执行结果的描述中,正确的是:
class Te"的相关试题:
[单选题]下列代码编译或执行结果的描述中,正确的是:
class Test{
public static void main(String args[]){
TestThread pm1 = new TestThread("One");
pm1.start();
TestThread pm2 = new TestThread("Two");
pm2.start();
}
}
class TestThread extends Thread{
private String sTname="";
TestThread(String s){
sTname = s;
}
public void run(){
for(int i=0;i<2;i++){
try {
sleep(1000);
} catch (InterruptedException e) {}
System.out.println(sTname+" ");
}
}
}
A.不能通过编译,TestThread 类中不能定义变量和构造方法
B.输出One One Two Two
C.输出Two One One Two
D.选项B 或C 都有可能出现
[单选题]下列代码的执行结果是
public class Test
{ public int aMethod()
{ static int i=0; i++; System.out.println(i); }
public static void main(String args[])
{ Test test = new Test(); test.aMethod(); } }
A.编译错误
B.0
C.1
D.运行成功,但不输出
[单选题]下列代码的执行结果是:
public class Test {
public static void main(String[] args) {
int[] x={0,1,2,3};
for(int i=0;i<3;i+=2){
try{
System.out.println(x[i+2]/x[i]+x[i+1]);
}catch(ArithmeticException e){
System.out.println("error1");
}catch(Exception e){
System.out.println("error2");
}
}
}
}
A.error1
B.error2
C.error1
error2
D.2
error2
[单选题]下列代码的编译或执行结果是:
public class MyVal {
public static void main(String[] args) {
MyVal m = new MyVal();
m.aMethod();
}
public void aMethod(){
boolean [] b = new Boolean [5];
System.out.println(b[0]);
}
}
A.1
B.null
C.0
D.编译错误
[单选题]下列程序输出结果为:public class test {public static void main(String args[]) {int a = 0;outer:for(int i=0;i
A.2
B.3
C.4
D.0
[单选题]下列程序的输出结果是:
public class Test{
public static void main(String[] args){
int [] array={2,4,6,8,10};
int size=6;
int result=-1;
try{
for(int i=0;iA.Catch---1
B.Catch---2
C.Catch---3
D.以上都不对