View on GitHub

我的学习笔记

好记性不如烂笔头

5.3 默认构造器

返回

//:initialization/DefaultConstructor.java
class Bird(){}

public class DefaultConstructor{
    public static void main(String[] args){
        Bird b=new Bird(); //Default !!!
    }
}
///:~
//:initialization/NoSynthesis.java
class Bird2{
    Bird2(int i){}
    Bird2(double d){}
}

public class NoSynthesis{
    public static void main(String[] args){
        //! Bird2 b=new Bird2() //No Default
        Bird2 b2 = new Bird2(1);
        Bird2 b3 = new Bird2(1.0);
    }
}
///:~

out

返回