💖 单选题
💖 填空题
💖 判断题
💖 程序阅读题
1. 读代码写结果
class A
{int m = 5;void zengA(int x){m = m + x;}int jianA(int y){return m - y;}
}class B extends A
{int m = 3;int jianA(int z){return super.jianA(z) + m;}
}public class Test
{public static void main(String[] args){A a1 = new A();A a2 = new A();B b = new B();A t = (A) b;A a3, a4;a3 = b;a4 = a1;a1.zengA(5);a3.zengA(6);b.m = 4;System.out.println(a1.m); // 【代码 1】System.out.println(a2.m); // 【代码 2】System.out.println(a3.m); // 【代码 3】System.out.println(a4.m); // 【代码 4】System.out.println(a3.jianA(1)); // 【代码 5】11-1+4 = 14}
}
2. 读代码写结果
abstract class A
{public abstract double f(double x, double y);
}class B extends A
{double m;public double f(double a, double b){return a * b + m;}
}public class E
{public static void main(String args[]){B b = new B();A a = b;b.m = 2.0;System.out.println(a.f(2.0, 3.0)); // 【代码 1】 2 * 3 + 2 = 8.0}
}
3. 读代码写结果
class A
{static int m = 5;void zengA(int x){m = m + x;}
}public class E
{public static void main(String args[]){A a1 = new A();A a2 = new A();a2.zengA(5);System.out.println(a1.m); // 【代码 1】System.out.println(a2.m); // 【代码 2】}
}
4. 读代码写结果
class A
{int x = 100;double y = 200.3;A(int x){x = x;}A(double y){this.y = y;}double B(){return x + y;}
}public class Test
{public static void main(String[] args){A a1 = new A(-80);// 构造方法:细节 x=x,相当于啥也没干System.out.println(a1.B()); // 【代码 1】100+200.3 = 300.3A a2 = new A(60.5);System.out.println(a2.B()); // 【代码 2】}
}
5. 读代码写结果
interface A
{public double f(double x, double y);
}class B implements A
{double m;public double f(double a, double b){return a * b + m;}
}public class E
{public static void main(String args[]){B b = new B();A a = b;b.m = 2.0;System.out.println(a.f(2.0, 3.0));// 2 * 3 + 2 = 8}
}