목록생성자 (1)
100세까지 코딩

문제 class Parent { int x = 100; Parent() { this(500); // this() : 자기자신 객체 생성자 호출 } Parent(int x) { this.x = x; // this : 객체 자기자신을 의미 } int getX() { return x; } } class Child extends Parent { int x = 4000; Child() { this(5000); } Child(int x) { this.x = x; } } public class Main { public static void main(String[] args) { Child obj = new Child(); System.out.println(obj.getX()); } } 풀기 전 생각 정답은 100이라..
JAVA
2023. 8. 10. 02:54