题目内容
1.请给出E类中标记的[结果1]、[结果2]。 class B{ int n; static int sum=0; void setN(int n) { this.n=n; } int getSum() { int i=1 ; while( i<=n) { sum=sum+i; i=i+2;} sum=sum*i; return sum; }}public class E{ public static void main(String args[]) { B b1=new B(),b2=new B(); b1.setN(3); b2.setN(3); int s1=b1.getSum(); int s2=b2.getSum();System.out.println(s1); //[结果1:______ ] System.out.println(s2);//[结果2:______ ] }}. 2. 请给出E类中标记的[结果1]、[结果2]。class A{ float n; A(float n){ this.n=n;} public void setFloatValue(float n) {this.n=n; } float FloatValue(){ return n; }}public class E{ public static void main(String args[]) { A a=new A(5); add(a); System.out.println(a.FloatValue()+8); //[结果2:______ ] }public static void add(A m){ int t=20; m.setFloatValue(t); System.out.println(m. FloatValue()); //[结果1:______ ] }}3. 请给出E类中标记的[结果1]、[结果2]。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();Lake lake =new Lake(); lake.setFish(redfish); lake.foodFish(120);System.out.println(redfish.weight); //[结果1:______ ]System.out.println(lake.fish.weight); //[结果2:______ ] }}4.请给出E类中标记的[结果1]、[结果2]。class A{ double f(double x,double y) { return x+y; }}class B extends A{ double f(float x,float y) { return x*y; }}public class E{ public static void main(String args[]) { B b=new B(); System.out.println(b.f(5,8)); //[结果1:______ ] System.out.println(b.f(8.0,12.0));// [结果2:______ ] }} 5. 请给出E类中标记的[结果1]、[结果2]。public class E{ public static void main(String args[]) { char a[ ]={ `5`, `4`, `3` ,`2`, `1`}; System.out.println(a.length); //[结果1:______ ] for(int i=0;i<=a.length/2;i++) { char c=a[i]; a[i]=a[a.length-i-1];a[a.length-i-1]=c; }for(int i=0;i
查看答案
搜索结果不匹配?点我反馈