【单选题】下面程序段的输出结果为______。
public class Test
int a, b;
Test()
a=100;
b=200;
Test(int x, int y)
a=X;
b=y;
public static void main(String args[])
Test Obj1=new Test(12,45);
System. out. println("a="+Obj1. a+"b="+Objl. b);
Test Obj2=new Test();
System. out. println("a="+Obj2. a+"b="+Obj2. b);
A.a=100 b=200
a=12 b=45
B.a=12 b=45
a=100 b=200
C.a=12 b=200
a=100 b=45
D.a=100 b=45
a=12 b=200
网考网参考答案:B
网考网解析:
[解析] 本题考查构造方法及构造方法重载。Test类有两个构造方法,即使用了方法重载技术。不带参数的构造方法对类的实例变量进行特定数值的赋值,而带参数的构造方法根据参数对类的实例变量进行赋值。TestObj1=newTest(12,45)语句调用的是Test (intx, inty),而TestObj2=newTest()调用的是Test(),注意根据参数个数来区分。
document.getElementById("warp").style.display="none";
document.getElementById("content").style.display="block";
查看试题解析出处>>
发布评论 查看全部评论