English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問一下,我要印出Apple has been planted,Apple is growing,...,Strawberry has been harvested;該修改哪裡??

class Apple{
private int treeAge;
public void plant(){
System.out.println("Apple has been planted");
}
public void grow(){
System.out.println("Apple is growing");
}
public void harvest(){
System.out.println("Apple has been harvested");
}
public int getTreeAge(){
return this.treeAge ;
}
public void setTreeAge (int treeAge) {
this.treeAge= treeAge;
}
}
class Grape{
private boolean seedless;
public void plant(){
System.out.println("Grape has been planted");
}
public void grow(){
System.out.println("Grape is growing");
}
public void harvest(){
System.out.println("Grape has been harvested");
}
public boolean getseedless(){
return this.seedless;
}
public void setseedless(boolean seedless){
this.seedless = seedless;
}
}
class Strawberry{
public void plant(){
System.out.println("Strawberry has been planted");
}
public void grow(){
System.out.println("Strawberry is growing");
}
public void harvest(){
System.out.println("Strawberry has been harvested");
}
}
public class java{
void main(){
Apple apple = new Apple();
Grape grape = new Grape();
Strawberry strawberry = new Strawberry();
}
}

2007-07-23 16:19:15 · 3 個解答 · 發問者 Elie 1 in 電腦與網際網路 程式設計

3 個解答

public class Java{
public static void main(String[] args){
Apple apple = new Apple();
Grape grape = new Grape();
Strawberry strawberry = new Strawberry();
apple.plant();
apple.grow();
apple.harvest();
grape.plant();
grape.grow();
grape.harvest();
strawberry.plant();
strawberry.grow();
strawberry.harvest();
}
}

紅色為修改部分,其它不變,即可達到你敘述的結果。
希望這樣有幫到你

豚仔

2007-07-23 18:08:37 · answer #1 · answered by 安迪豬 6 · 0 0

Java 程式,一個 java 檔案可以包含數個類別,唯一的限制是只能包含一個 public 類別。

2007-07-23 18:50:05 · answer #2 · answered by ? 7 · 0 0

Java 程式…,一個類別只能存成一個 java 檔案。

2007-07-23 17:37:04 · answer #3 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers