1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
將靜態(tài)放在主要方法簽名中。
創(chuàng)建靜態(tài)內(nèi)部類,因?yàn)槟朐陟o態(tài) main 方法中訪問這些類。
正確代碼:
public class monkey {
public static void main(String[] args) {
Fruit jeff = new Fruit("ree");
Fruit mike = new Apple("ree");
jeff.talk();
mike.talk();
}
static class Fruit {
String sound;
public Fruit(String s) {
sound = s;
}
public void talk() {
System.out.print(sound);
}
}
static class Apple extends Fruit {
public Apple(String s) {
super(s);
}
}
}
添加回答
舉報(bào)