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

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

来源:网络收集 时间:2026-01-29
导读: System.out.println( \= \+ myCount.count); System.out.println(\= \times); } public static void increment(Count c, int times) { c.count++; times++; } } class Count { int count; Count(int c) { count = c

System.out.println(

\= \+ myCount.count); System.out.println(\= \times);

} public static void increment(Count c, int times) { c.count++; times++; } } class Count { int count; Count(int c) { count = c; } Count() { count = 1; } } 1、 101 2、 100 3、 99

4、 98 5、 0 答案 5 第 113题 Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate. 1、 x contains an array of ten int values.

2、 x contains an array of ten objects of the Circle type.

3、 x contains a reference to an array and each element in the array can hold a reference to a Circle object.

4、 x contains a reference to an array and each element in the array can hold a Circle object.

答案 3 第114题 Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true? 1、 dates is null. 2、 dates[0] is null.

3、 dates = new java.util.Date[5] is fine, which assigns a new array to dates. 4、 dates = new Date() is fine, which creates a new Date object and assigns to dates. 答案 2 3 第 115题 Which of the following statements are true about an immutable object?

1、 The contents of an immutable object cannot be modified. 2、 All properties of an immutable object must be private.

3、 All properties of an immutable object must be of primitive types.

4、 An object type property in an immutable object must also be immutable.

5、 An immutable object contains no mutator methods. 答案 1 2 4 5 第 116题 What is the printout for the first statement in the main method?

public class Foo { static int i = 0; static int j = 0; public static void main(String[] args) { int i = 2; int k = 3; { int j = 3;

System.out.println(\ } k = i + j;

System.out.println(\ System.out.println(\ } }

1、 i + j is 5 2、 i + j is 6 3、 i + j is 22

4、 i + j is 23 答案 4 第 117题 What is the printout for the second statement in the main method? public class Foo { static int i = 0; static int j = 0; public static void main(String[] args) { int i = 2; int k = 3; { int j = 3;

System.out.println(\ } k = i + j;

System.out.println(\ System.out.println(\ } }

1、 k is 0 2、 k is 1 3、 k is 2 4、 k is 3

答案 3 第 118题 What is the printout for the third statement in the main method?

public class Foo { static int i = 0; static int j = 0; public static void main(String[] args) { int i = 2; int k = 3; { int j = 3;

System.out.println(\ } k = i + j;

System.out.println(\ System.out.println(\ } }

1、 j is 0 2、 j is 1 3、 j is 2

4、 j is 3 答案 1 第 119题 Analyze the following code:

class Circle { private double radius; public Circle(double radius) { radius = radius; } }

1、 The program has a compilation error because it does not have a main method.

2、 The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.

3、 The program has a compilation error because you cannot assign radius to radius.

4、 The program does not compile because Circle does not have a default constructor.

答案 2 第 120题 Analyze the following code: class Test { private double

i;

public

Test(double } public Test() {

System.out.println(\constructor\ public void t() {

System.out.println(\ } }

1、 this.t() may be replaced by t(). 2、 this.i may be replaced by i.

3、 this(1) must be called before System.out.println(\constructor\

4、 this(1) must be replaced by this(1.0). 答案 1 3 第 121题 Object-oriented programming allows you to derive new classes from existing classes. This is called ____________. 1、 encapsulation 2、 inheritance

3、 abstraction 4、 generalization 答案 2 第 122题 Suppose you create a class Cylinder to be a subclass of Circle. Analyze the following code: class Cylinder extends Circle { double length;

Cylinder(double radius) { Circle(radius); } }

1、 The program compiles fine, but you cannot create an instance of Cylinder because the constructor does not specify the length of the cylinder. 2、 The program has a compile error because you attempted to invoke the Circle class s constructor illegally.

3、 The program compiles fine, but it has a runtime error because of invoking the Circle class s constructor illegally. 答案 2 第 123题 Analyze the following code: import java.util.StringTokenizer; public class A extends StringTokenizer {

i)

{ this.t(); this.i = i;

}

1、 The program has a compilation error because A does not have a default constructor.

2、 The program has a compilation error because the default constructor of

A

invokes

the

default

constructor

of

StringTokenizer,

but

StringTokenizer does not have a default constructor.

3、 The program would compile fine if you add the following constructor into A:

A(String s) { }

4、 The program would compile fine if you add the following constructor into A: A(String s) { super(s); } 答案 2 4 第 124题 Analyze the following code: public class Test extends A { public static void main(String[] args) { Test t = new Test(); t.print(); } } class A { String s; A(String s) { this.s = s; } public

void

print()

{ System.out.println(s); } }

1、 The program does not compile because Test does not have a default constructor Test().

2、 The program has an implicit default constructor Test(), but it cannot be compiled, because its s …… 此处隐藏:3511字,全部文档内容请下载后查看。喜欢就下载吧 ……

Java练习题1(有答案)(11).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)