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

2019-08-31 09:26

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 super class does not have a default constructor. The program would compile if the constructor in the class A were removed. 3、 The program would compile if a default constructor A(){ } is added to class A explicitly.

4、 The program compiles, but it has a runtime error due to the conflict on the method name print.

答案 2 3 第 125题 What is the output of running class C? class A { public A() { System.out.println(


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

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

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

马上注册会员

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