개발자노트
클래스) 생성자와 기본 생성자의 관계(인자값)
hansummer
2022. 6. 17. 00:55
package unnamed;
class A {
int x;
int y;
void show() {
System.out.println(x + " / " + y);
}
A() {
this(1, 2);
System.out.println("111");
}
A(int x) {
this(x, 3);
System.out.println("222");
}
A(int x, int y) {
this.x = x;
this.y = y;
System.out.println("333");
}
}
public class Test02_2 {
public static void main(String[] args) {
A a1 = new A(13);
A a2 = new A();
a1.show();
a2.show();
}
}
출력값 =
333
222
333
111
333
13 / 3
1 / 2
15 / 34