以下是我的代码。我没有得到什么错误。任何人都可以引导。覆盖构造函数类
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