A-A+

阅读下面程序 public class MyVal { public static void

2022-08-05 20:19:38 问答库 阅读 171 次

问题详情

阅读下面程序 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的字段。

考点:程序