下面是我的代码。我不明白这是什么错误。有谁可以指导一下吗。
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;
}
}
运行时显示为“错误:无法找到或加载主类 State$Place”
由于输出需要:“首都是华盛顿特区”而不是(大写+
" " + "是" + " " + 国家/地区 + " " +"首都。")
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 // Inheritance
static void display()
{
System.out.println("Capital is Washington D.C.");
}
public static void main(String[] args)
{
State st = new State();
st.display(); // to print sub class method
display(); // to print same class method
//st = pl; No idea of this point ..
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)