객체 자식을 가르키는 참조변수. 인스턴스 매서드(생성자)내에만 존재
조상의 멤버를 자신의 멤버와 구별할 때 사용
public class Super {
public static void main(String[] args) {
Child c = new Child();
c.method();
}
}
class Parent { int x = 10; /* super.x */ }
class Child extends Parent {
int x = 20; //this.x
void method() {
System.out.println("x=" + x);
System.out.println("this.x=" + this.x);
System.out.println("super.x=" + super.x);
}
}
-------------------------------------------------------------
x=20
this.x=20
super.x=10
'JAVA' 카테고리의 다른 글
객체지향 static, final, abstract 제어자 (0) | 2022.09.26 |
---|---|
객체지향 super() - 조상의 생성자 (0) | 2022.09.26 |
객체지향 메서드 오버라이딩(overriding) (0) | 2022.09.25 |
객체지향 포함 관계 (0) | 2022.09.25 |
객체지향 상속(inheritance) (1) | 2022.09.25 |