教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

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

来源:网络收集 时间:2026-01-29
导读: } } 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.printl

} } 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 答案 1 第 133题 Given the following code, find the compile error?

public class Test { public static void main(String[]

args)

{

m(new m(new

GraduateStudent()); Object()); }

public static void m(Student x) { System.out.println(x.toString()); } } class GraduateStudent extends Student { }

class

Student {

public

extends String

Student()); m(new Person()); m(new

Person

toString() { return \ } } class Person extends Object } }

1、 m(new GraduateStudent()) causes an error 2、 m(new Student()) causes an error

{

public

String

toString() { return \

3、 m(new Person()) causes an error 4、 m(new Object()) causes an error 答案 3 4 第 134题 Given the following classes and their objects: class C1 {}; class C2 extends C1 {}; class C3 extends C1 {}; C2 c2 = new C2(); C3 c3 = new C3();

Analyze the following statement: c2 = (C2)((C1)c3);

1、 c3 is cast into c2 successfully.

2、 You will get a runtime error because you cannot cast objects from sibling classes.

3、 You will get a runtime error because the Java runtime system cannot perform multiple casting in nested form. 4、 The statement is correct. 答案 2 第 135题 Given the following code:

class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {} C1 c1 = new C1(); C2 c2 = new C2(); C3 c3 = new C3(); C4 c4 = new C4();

Which of the following expressions evaluates to false? 1、 c1 instanceof C1 2、 c2 instanceof C1

3、 c3 instanceof C1 4、 c4 instanceof C2 答案 4 第 136题 You can assign _________ to a variable of Object[] type. 1、 new char[100] 2、 new int[100] 3、 new double[100]

4、 new String[100] 5、 new java.util.Date[100] 答案 4 5 第 137题 Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of

the following methods will cause the list to become [Beijing, Chicago, Singapore]?

1、 x.add(\ 2、 x.add(0, \ 3、 x.add(1, \

4、 x.add(2, \ 答案 3 第 138题 Suppose ArrayList x contains two strings [Beijing, Singapore].

Which of the following method will cause the list to become [Beijing]? 1、 x.remove(\ 2、 x.remove(0)

3、 x.remove(1) 4、 x.remove(2) 答案 1 3 第 139题 Analyze the following code: ArrayList list = new ArrayList();

list.add(\

list.set(3,

list.add(\list.add(\\

1、 The last line in the code causes a runtime error because there is no element at index 3 in the array list.

2、 The last line in the code has a compile error because there is no element at index 3 in the array list.

3、 If you replace the last line by list.add(3, \compile and run fine.

4、 If you replace the last line by list.add(4, \compile and run fine.

答案 1 3 第 140题 What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package? 1、 public 2、 private 3、 protected

4、 Use the default modifier. 答案 3 第 141题 Which of the following classes cannot be extended? 1、 class A { }

2、 class A { private A();}

3、 final class A { } 4、 class A { protected A();} 答案 3 第 142题 The getValue() method is overridden in two ways. Which one is correct? I:

public class Test {

…… 此处隐藏:1538字,全部文档内容请下载后查看。喜欢就下载吧 ……
Java练习题1(有答案)(14).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521351.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)