📜  java代码示例中构造函数的语法

📅  最后修改于: 2022-03-11 14:52:02.399000             🧑  作者: Mango

代码示例1
public class MyClass {//this is an example of a class with a non default constructor  
    private int number = 0;

    public MyClass() {
    }

    public MyClass(int theNumber) {//this is the constructor
        //acces modifiers+constructor name(it needs to be the same as the class name)+parameters
        this.number = theNumber;
    }
}