单选题下列代码的编译或执行结果是(  )。 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 1B nullC 0D 编译错误

题目
单选题
下列代码的编译或执行结果是(  )。 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

编译错误

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

阅读下列代码

Public class Person{

Static int arr[ ] = new int (10);

Public static void main (String args ) {

System.out.println(arr[9]);

}

}

该代码运行的结果是

A )编译时将产生错误

B )编译时正确,运行时将产生错误

C )输出 0

D )输出空


正确答案:C

第2题:

下列代码的执行结果是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.运行成功,但不输出


正确答案:A
解析:static不能修饰局部变量。

第3题:

下面程序执行后,输出的结果是( )。 public class Test { public static void main (String[] )args) { boolean m=true; if(m==false) System.out.println("假"); else if(m====true) System.out.println("真"); else System.out.println ("错误"); } }

A.真

B.假

C.错误

D.编译出错


正确答案:A
解析:这是一个if-else结构的程序,判断条件是布尔变量m是否为真,若为真则打印“真”,若为假则打印“假”,其他情况下打印“错误”。

第4题:

阅读下列代码: public class Person{ static int arr[]=new int[10]; public static void main(String args){ System.out.println{arr[9]); } } 该代码的运行结果是( )。

A.编译时将产生错误

B.编译时正确,运行时将产生错误

C.输出零

D.输出空


正确答案:C
C。【解析】arr[]为整型数组,分配地址后默认值为0,所以创建数组时也是对每个数组元素赋初值0。

第5题:

下列程序的执行结果是______。 class A5 extends Thread { boolean b; A5 (boolean bb) { b = bb; } public void run() { System.out.println(this.getName() + "运行"); } } public class Testl5 { public static void main(String[] args) { A5 a1 = new A5(true); A5 a2 = new A5(false); if(a1.b) A1.start(); if (a2 .b) A2.start(); } }

A.Thread-0

B.Thread-1

C.Thread-0

D.Thread-1 Thread-1 Thread-0


正确答案:A
解析:类A5继承了Thread类,并且重写了Thread类的run()方法,调用本线程的getName()方法打印出系统给本线程定义的名称。在main()方法中,a1和a2是A5的对象,它们对应的系统默认的线程名称分别是Thread—0和Thread—1,根据类A5的类变量b的布尔值控制哪一个线程调用start()方法,这里应该是a1线程被调度执行。

第6题:

下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic 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.运行成功,但不输出


正确答案:A

第7题:

阅读下面代码 public class Person { static int arr[]=new int[10]; public static void main(String args) { System.out.println(arr[9]); } } 该代码的运行结果是

A.编译时将产生错误

B.编译时正确,运行时将产生错误

C.输出零

D.输出空


正确答案:B
解析:Java程序中,main()方法的格式为public staric void main(String args[]) { },返回值为void,参数必须为字符数组。本题目程序的参数不是字符数组,编译不会出错,但是运行时会找不到main()方法,程序无法执行。

第8题:

下列代码的编译或执行结果是______。

public class MyVal{

puhlic 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) 编译错误

A.

B.

C.

D.


正确答案:B

第9题:

阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是

A.1

B.null

C.

D.编译不能过


正确答案:C
解析:编译能通过,但不在控制台输出任何信息。程序只是实例化了一个布尔类型的数组,且由于此数组为局部变量,不会自动初始化,故其中值都为null。

第10题:

下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }

A.1

B.null

C.0

D.编译错误


正确答案:A
A。【解析】boolean类型的变量值只有ture或false,b[0]的默认初始值为false。

更多相关问题