Java练习题1(有答案)(9)

2019-08-31 09:26

\ } } class B extends A { public B() { System.out.println(

\ } } public class C {

public static void main(String[] args) { B b = new B(); } }

1、 Nothing displayed

2、 \

3、 \is invoked\

4、 \is invoked\

5、 \default constructor of A is invoked\ 答案 3 第 126题 Analyze the following code: public class Test { public static void main(String[] args) { B b = new B(); b.m(5); System.out.println(\ } } class A { int i; public void m(int i) { this.i = i;

} } class B extends A { public void m(String s) { } }

1、 The program has a compilation error, because m is overridden with a different signature in B.

2、 The program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.

3、 The program has a runtime error on b.i, because i is not accessible from b. 4、 The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

答案 4 第 127题 Analyze the following code:

public class Test {

public static void main(String[] args) { Object a1 = new A(); Object a2 = new Object(); System.out.println(a1); System.out.println(a2); } } class A { int x; public String toString() { return \ } }

1、 The program cannot be compiled, because System.out.println(a1) is wrong and it should be replaced by System.out.println(a1.toString()); 2、 When executing System.out.println(a1), the toString() method in the Object class is invoked.

3、 When executing System.out.println(a2), the toString() method in the Object class is invoked.

4、 When executing System.out.println(a1), the toString() method in the A class is invoked.

答案 3 4 第 128题 What is the output of the following code: public class Test {

public static void main(String[] args) { Object o1 = new Object(); Object o2 = new Object();

System.out.print((o1 == o2) + \ } }

1、 false false 2、 true true

3、 false true 4、 true false 答案 1 第 129题 What is the output of the following code: public class Test {

public static void main(String[] args) {

String s1 = new String(\ String s2 = new String(\

System.out.print((s1 == s2) + \ } }

1、 false false 2、 true true 3、 false true

4、 true false 答案 3 第 130题 Analyze the following code. //

Program

1:

public class Test {

public static void main(String[] args) { Object a1 = new A(); Object a2 = new A();

System.out.println(a1.equals(a2)); } } class A { int x; public boolean equals(Object a) { return this.x == ((A)a)x; } } //

Program

2:

public class Test {

public static void main(String[] args) { Object a1 = new A(); Object a2 = new A();

System.out.println(a1.equals(a2)); } } class A { int x; public boolean equals(A a) { return this.x == a.x; } }

1、 Program 1 displays true and Program 2 displays true 2、 Program 1 displays false and Program 2 displays true 3、 Program 1 displays true and Program 2 displays false 4、 Program 1 displays false and Program 2

displays false 答案 3 第 131题 Analyze the following code. //

Program

1:

public class Test {

public static void main(String[] args) { Object a1 = new A();

Object a2 = new A();

System.out.println(a1.equals(a2)); } } class A { int x; public boolean equals(A a) { return this.x == a.x; } } //

Program

2:

public class Test {

public static void main(String[] args) { A a1 = new A(); A a2 = new A();

System.out.println(a1.equals(a2)); } } class A { int x; public boolean equals(A a) { return this.x == a.x; } }

1、 Program 1 displays true and Program 2 displays true 2、 Program 1 displays false and Program 2 displays true 3、 Program 1 displays true and Program 2 displays false 4、 Program 1 displays false and Program 2 displays false 答案 2 第 132题 Analyze the following code. //

Program

1

public class Test {

public static void main(String[] args) { Object a1 = new A(); Object a2 = new A();

System.out.println(((A)a1).equals((A)a2));


Java练习题1(有答案)(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017-2018学年度第一学期小学教研工作计划及打算

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: