首页 > 试题广场 >

说出下列E类中【代码1】~【代码3】的输出结果。 clas

[问答题]
说出下列E类中【代码1】~【代码3】的输出结果。
class Fish{
    int weight=1;
}
class Lake{
    Fish fish;
    void setFish(Fish s){
        fish =s;
    }
    void foodFish(int m){
        fish.weight=fish.weight+m;
    }
}
public class E{
       public static void main(String args[ ]){
            Fish redFish = new Fish();
            System.out.println(redFish.weight);     //【代码1】
            lake.setFish(redFish);
            lake.foodFish(120);
            System.out.println(redFish.weight);     //【代码2】
            System.out.println(lake.fish.weight);    //【代码3】
       }
 }

代码错的
发表于 2020-03-15 17:18:36 回复(0)