Java 생성자와 오버로딩 예제 – 5

public class Student { 
    private int number; 
    private String name; 
    private int age; 
 
    Student() { 
        this(4,"hello",10); 
    } 
 
    Student(int number, String name, int age) { 
        this.number = number; this.name = name; this.age = age; 
    } 
 
    public void print(){ 
        System.out.println("number = " + number + " name = " + name + " age = " + age); 
    } 
} 

 

public class StudentTest { 
    public static void main(String[] args) { 
        Student std = new Student(); 
        Student std2 = new Student(1,"name",2); 
 
        std.print(); 
        std2.print(); 
    } 
}