Customer.java:17: error: cannot find symbol
super.display();
^
symbol: method display()
1 error
這是編譯我的程序時發生的情況。如何在Customer
子類中顯示對象數據?在Java中調用超級方法
import java.util.Scanner;
public class Person {
private String name;
private String address;
private String number;
//No Argument constructor//
public Person() {
name = "";
address = "";
number = "";
}
//Explicit value constructor//
public Person(String num, String nam, String add) {
number = num;
name = nam;
address = add;
}
//Accessor method//
public String getName() {
return name;
}
//Mutator method//
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelephoneNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String toString() {
return name + "\n" + address + "\n" + number;
}
}
子類:
public class Customer extends Person {
public Customer(String num, String nam, String add) {
super(num, nam, add);
}
public boolean checkResponse(char response) {
if (response == 'Y') {
return true;
}
return false;
}
public void display() {
super.display();
}
}
'super.display();'是問題所在。它不在超類。 – Santosh
@Sandhu:請不要在您正在編輯的問題中添加更多內容。它混淆了實際代碼的意圖,並可能爲其他人解決提供紅鯡魚。 – Makoto
@Makoto我剛剛格式化了代碼。就這樣。我沒有再添加任何東西。請在編輯歷史記錄中重新檢查我的編輯 –