根据下列程序给出执行结果,给出输出结果 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 lake=new Lake(); lake.setFish(redFish); lake.foodFish(120); System.out.print(redFish.weight); //【代码2】 System.out.println(lake.fish.weight); //【代码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 lake=new Lake(); lake.setFish(redFish); lake.foodFish(120); System.out.print(redFish.weight); //【代码2】 System.out.println(lake.fish.weight); //【代码3】 } }
发布时间:2024-10-24 10:53:43