挑错题:下列ABCD注释标注的哪行代码有错误?class E {int x;public void f(int n) {int m; //Aint t = x+n; //Bint y = x+m; //Cm = 10;y = x+m; //D}}
查看答案
挑错题:下列ABCD注释标注的哪行代码有错误?class Tom {int x;static int y;void showXY(){System.out.printf("%d,%d\n",x,y);}static void showY() {System.out.printf("%d\n",y);}}public class E {public static void main(String aqgs[]){Tom.y = 100; //ATom cat = new Tom();cat.x = 100;cat.y = 200; //BTom.x = 300; //Ccat.showXY();Tom.showY(); //D}}
A
B
C
D
阅读程序题(给出【代码】注释标注的代码的输出结果)class Fish {int weight = 1;}class Lake {Fish fish;void setFish(Fish s){fish = s;}void foodFish(int m) {fish.weight=fish.weight+m;}Fish getFish(){fish.weight -= 10;return fish;}}public class E {public static void main(String args[]) {Fish redFish = new Fish();Lake lake = new Lake();lake.setFish(redFish);lake.foodFish(120);int w = lake.fish.weight;Fish fishOK = lake.getFish();System.out.printf("%d:%d:%d",w,lake.fish.weight,fishOK.weight); //【代码】}}
阅读程序题(给出【代码】注释标注的代码的输出结果)class B {int x = 100,y = 200;public void setX(int x) {x = x;}public void setY(int y) {this.y = y;}public int getXYSum() {return x+y;}}public class E {public static void main(String args[]) {B b = new B();b.setX(-100);b.setY(88);System.out.printf("%d:%d:%d",b.x,b.y,b.getXYSum());//【代码】}}
阅读程序题(给出【代码】注释标注的代码的输出结果)class Tom {static int sum;int getSum(int ... item ){for(int n:item){sum += n;}return sum;}}public class E {public static void main(String args[]) {Tom cat1 = new Tom();Tom cat2 = new Tom();int resultOne = cat1.getSum(1,2,3,4);int resultTwo = cat2.getSum(10,30);System.out.printf("%d:%d",resultOne,resultTwo); //【代码】}}