개발자노트
클래스) 생성자와 기본 생성자의 관계 이해(점,좌표찍기)
hansummer
2022. 6. 17. 00:56
package class02;
class Point {
int x;
int y;
void showInfo() {
System.out.println("P(" + this.x + "," + this.y + ")");
}
Point() {
this(0, 0);
System.out.println("기본 생성자");
}
Point(int x) {
this.x = x;
this.y = x;
}
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
public class Test03 {
public static void main(String[] args) {
Point p1 = new Point(10, 20);
Point p2 = new Point();
Point p3 = new Point(1);
p1.showInfo();
p2.showInfo();
p3.showInfo();
}
}