2017-09-28 5 views
0

이 표시됩니다. 이 예제 결과는 다음과 같습니다. feline cougar c c부모 클래스의 변수에 액세스하면 하위 클래스 변수

그러나 super.type 메서드를 호출합니다.

class Feline { 
    public String type = "f "; 
    public Feline() { 
    System.out.print("feline "); 
    } 
} 
public class Cougar extends Feline { 
    public Cougar() { 
    System.out.print("cougar "); 
     } 
     void go() { 
     type = "c "; 
     System.out.print(this.type + super.type); 
    } 
     public static void main(String[] args) { 
     new Cougar().go(); 
     } 
     } 

나는 feline cougar c f.

답변

0

하나의 변수 만 있습니다. 그러나 해당 변수에 액세스하면 동일한 값을 제공합니다.

관련 문제