ConstructorOverLoad
class Student{
private String name="lucy";
private int age=18;
Student(){
System.out.println("invoke no parameter construcor method");
System.out.println("name is "+name+",age is "+ age);
}
Student(String n){
name=n;
System.out.println("invoke construcor method with one parameter");
System.out.println("name is "+name+",age is "+ age);
}
Student(String n,int i){
name=n;
age=i;
System.out.println("invoke construcor method with two parameters");
System.out.println("name is "+name+",age is "+ age);
}
}
public class ConstructorOverLoad {
public static void main(String[] args) {
// TODO 自动生成的方法存根
new ConstructorOverLoad();
new Student();
new Student("tom");
new Student("jack",25);
}
}