Super

2021. 1. 15. 10:542021/JOB DA STUDY

부모 클래스로부터 상속받은 필드나 메소드를 자식 클래스에서 참조하는데 사용하는 참조 변수

 

인스턴스 변수명과 지역 변수명이 동일한 경우, this.인스턴스변수로 사용하는 것 처럼

부모클래스와 자식크래스 멤버의 이름이 같은 경우 super를 사용해 구별

 

class Parent{
    int a=10;
}

class Child extends Parent{
    int a= 20;

    void display(){
        System.out.println(a);
        //20
        System.out.println(this.a);
        //20
        System.out.println(super.a);
        //10
    }
}

public class Inheritance{
    public static void main(String[] args){
        Child ch = new Child();
        ch.display();
    }
}