조상의 생성자 super()
-생성자의 첫줄에는 반드시 생성자를 호출해야 한다.
super()아니면 this()를 호출해야함
-그렇지 않으면 컴파일러가 생성자의 첫 줄에 super();(조상의 생성자)를 삽입
class Point{
int x;
int y;
Point(){
this(0,0);
}
Point(int x,int y){
this.x = x;
this.y = y;
}
}
위의 코드를 컴파일하면 아래와 같이 된다.
class Point extends Object{
int x;
int y;
Point(){
this(0,0);
}
Point(int x,int y){
super(); //Object(); 모든 클래스의 조상은 Object클래스니까
this.x = x;
this.y = y;
}
}