问题 单项选择题

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

A.1

B.null

C.""

D.编译不通过

答案

参考答案:D

解析: 语句boolean b[]=new Boolean[5];存在错误,类型不兼容,左边为基本类型,右边为类java.lang.Boolean。Boolean类将基本类型为boolean的值包装在一个对象中。一个Boolean类型的对象只包含一个类型为boolean的字段。

单项选择题
单项选择题