Java출력 결과기초 · 10점#생성자#클래스#this

283. this(...)로 다른 생성자 부르기

다음 Java 프로그램의 실행 결과를 쓰시오.

1class Point {
2 int x, y;
3
4 Point() {
5 this(1, 1);
6 }
7
8 Point(int x, int y) {
9 this.x = x;
10 this.y = y;
11 }
12}
13
14public class Main {
15 public static void main(String[] args) {
16 Point p = new Point();
17 Point q = new Point(4, 2);
18 System.out.println((p.x + q.x) + " " + (p.y * q.y));
19 }
20}

💡 Java에서 참·거짓은 true / false처럼 모두 소문자로 써요.

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.