A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© why910107 中级黑马   /  2016-6-12 21:32  /  318 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

36.在java中,以下程序的输出结果是(  )
class Point  {     
int x; 
         boolean y;     
void output()     { 
               System.out.println(x);        
System.out.println(y);      

            public static void main(String[] args)     { 
                Point pt =new Point();        
         pt.output();    
 }  
 } 
A.        运行错误 
B.        0 ture  
C.  0 false
D.        0 0 

2 个回复

倒序浏览
0,false  成员变量有默认的初试值的
回复 使用道具 举报
你的格式有问题,不能编译运行
class Point {
        int x;
        boolean y;

        void output() {
                System.out.println(x);
                System.out.println(y);
        }
}
public class Test_02{
        public static void main(String[] args) {
                Point pt = new Point();
                pt.output();
        }
}
答案是C。0,false。
成员变量中,基本数值类型默认值是0,boolean默认是false。
局部变量中,未赋值就会报错。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马