以下是我的代碼。我沒有得到什麼錯誤。任何人都可以引導。覆蓋構造函數類
class State {
static String country;
static String capital;
State() // Constructor
{
country = "America's";
capital = "Washington D.C";
}
static void display() {
System.out.println(capital + " " + "is" + " " + country + " " + "capital.");
}
}
class Place extends State // Method Overriding
{
static void display() {
System.out.println("Capital is Washington D.C.");
}
public static void main(String[] args) {
State st = new State();
Place pl = new Place();
st.display();
pl.display();
st = pl;
}
}
在運行它顯示爲「錯誤:無法找到或加載主類國家$地方」
As the output needs: "Capital is Washington D.C." instead of (capital + " " + "is" + " " + country + " " +"capital.")
什麼目的呢?? 'st = pl;' –
它對我很好用。 –
顯示「Capital is Washington D.C.」而不是(大寫+「」+「是」+「」+ country +「」+「capital。」) – Arvind