day16_BindingTest2

육희영·2021년 10월 28일
0
package com.java1.day16;

public class BindingTest2 {
	public static void main(String[] args) {
		Parent2 p = new Child2(); // 자식 -> 부모
		Child2 c = new Child2();

		System.out.println("p.x = " + p.x);
		p.method();

		System.out.println("c.x = " + c.x);
		c.method();

	}

}

class Parent2 {
	int x = 100;

	void method() {
		System.out.println("Parent Mthod");
	}
}

class Child2 extends Parent2 {
} // 아무것도 정의되어 있지 않고 단순히 조상으로 부터 멤버들을 상속받는다.
//그렇기 때문에 참조변수의 타입에 관계없이 조상의 멤버들을 사용하게 된다.

출력결과

p.x = 100
Parent Mthod
c.x = 100
Parent Mthod

0개의 댓글

관련 채용 정보