Java各个变量默认值

package newqueastion;

public class NewQuestion {
    byte b;
    short s;
    int i;
    long l;
    float f;
    double d;
    int[] arr=null;
    int[] arr1;
    boolean boo;
    char c;
    String str;
    public boolean testMethon(){
        return true;
    }
}

package newqueastion;

public class Test {
    public static void main(String[] args) {
        //正确的实例化方式 打印true 0 null
        NewQuestion c=new NewQuestion();
        System.out.println(c.testMethon()+"\t");
        //成员变量不写会有默认值

        System.out.println("------默认值测试------");
        //byte、short、int、long默认值为0
        System.out.println(c.b);
        System.out.println(c.s);
        System.out.println(c.i);
        System.out.println(c.l);
        //float、double默认值为0.0
        System.out.println(c.f);
        System.out.println(c.d);
        //数组默认null
        System.out.println(c.arr);
        System.out.println(c.arr1);
        //boolean 为false
        System.out.println(c.boo);
        //char类型 \u0000
        System.out.println(c.c);
        //String类型 null
        System.out.println(c.str);

    }
}

运行结果图片

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值