목록상속 (2)
100세까지 코딩

문제 public class Main { public static void main(String[] args) { A test = new B(); System.out.println(test.X); test.func1(); } } class A { public int X = 500; public void func1() { System.out.println("클래스 A입니다."); } } class B extends A { public int X = 1000; public void func1() { System.out.println("클래스 B입니다."); } } 풀기 전 생각 1000, 클래스 B입니다. 가 출력될 것이라고 생각 정보처리기사 공부할 때 동적 바인딩만 나왔고 다 맞았었기 때문 풀이 자바에서 ..

문제 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이라..