构造函数

复制代码
public class Const {
    private Integer a, b, c;//int类型的初始值是0,Integer的初始值是null,所以main方法输出null
    public void Const() {//不要粗心大意,去掉void才是构造函数,
        System.out.println("构造函数");
        a = 3;
        b = 5;
        this.c = a + b;
    }
    public void test() {
        System.out.println("The value of c :" + c);
    }
    public static void main(String[] args) {
        Const c = new Const();
        c.test();
    }
}
复制代码

 

本文作者:孤沉

本文链接:https://www.cnblogs.com/guchen33/articles/16724774.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   孤沉  阅读(2)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开