2014-12-09 1 views
0

하위 클래스의 맨 아래에 수퍼 클래스에서 3 줄이 필요하며 switch 문을 사용하여 인쇄해야합니다. 분명히 void이기 때문에 System.out.println(super.display());을 인쇄하지 않습니다.수퍼 클래스에서 하위 클래스로 인쇄하려고합니다.

어떻게해야할지 모르겠습니다.

슈퍼 클래스 :

public void display() 
{ 
     String fullLocation = ""; 

     switch (location) 
     { 

       case 'N': case 'n': fullLocation = "North London"; 
       break; 
       case 'S': case 's': fullLocation = "South London"; 
       break; 
       case 'E': case 'e': fullLocation = "East London"; 
       break; 
       case 'W': case 'w': fullLocation = "West London"; 
       break; 
       default: fullLocation = "Central London"; 
       break; 

     } 
     System.out.println("The address of this property is at " + address + "."); 
     System.out.println("This property is in " + fullLocation); 
     System.out.println("This property has " + bedrooms + " bedrooms"); 
} 

서브 클래스 :

public void display() 
{ 

    String buyer = purchaser; 

    if(sold == true){ 

     *System.out.print(super); ???* 

     System.out.println("The price of this property is £" + price + "."); 
     System.out.println("The owner of this property is " + purchaser + "."); 
    } 
    else{ 
     System.out.println("The startic price for this property is £" + price + "."); 
     System.out.println("The property is still on the Market"); 
    } 
} 

답변

1

그냥 메서드의 수퍼 클래스 버전을 호출하지 않습니다 super 코딩. 슈퍼 클래스의 방법이 있기 때문에, 당신은 그 줄에서 System.out.println을 제거 할 수 있습니다

super.display(); 

: 그것은 슈퍼 클래스의 인스턴스 인 것처럼 슈퍼 클래스의 메소드를 호출하는 경우, 당신은 점 표기법과 메서드를 호출 키워드 super를 처리 할 수 그것의 자신의 인쇄 진술.

+0

고맙습니다. –

0

그냥 쓰기 super.display(), System.out.println은 필요하지 않습니다.