Java考试题1

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Java考试题1

Part 1: Single-choice questions(15 points)

1.The constructor of a class that adheres to the Singleton design pattern must

have _____ visibility.

A. private

B. protected

C. package

D. public

2.Which method is used to define the execution body of a thread?

A. start()

B. init()

C. run()

D. main()

3.Which modifier should be applied to a method for the lock of the object this to be obtained prior to executing any of the method body?

A. final

B. static

C. abstract

D. protected

E. synchronized

4. A Button is positioned in a Frame. Its size is not affected when

the Frame is resized. Which layout manager should be used?

A. FlowLayout

B. North and South of BorderLayout

C. East and West of BorderLayout

D. GridLayout

5.Given the following code:

1) class Example{

2) String str;

3) public Example(){

4) str= "example";

5) }

6) public Example(String s){

7) str=s;

8) }

9) }

10) class Demo extends Example{

11) }

12) public class Test{

13) public void f () {

14) Example ex = new Example("Good");

15) Demo d = new Demo("Good");

16) }

Which line will cause an error?

A. line 3

B. line 6

C. line 10

D. line 14

E. line 15

6.What would be the result of attempting to compile and run the following piece of code?

public class Test {

public int x;

public static void main(String args[]){

System.out.println("Value is " + x);

}

}

A. The output "Value is 0" is printed.

B. Non-static variable x cannot be referenced from a static context..

C. An "illegal array declaration syntax" compiler error occurs.

D. A "possible reference before assignment" compiler error occurs.

E. An object of type ArrayIndexOutOfBoundsException is thrown.

7. You need to create a class that will store a unique object elements.

You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?

A. Set

B. List

C. Map

D. Vector

8. You have these files in the same directory. What will happen when you attempt to compile and run Class1.java //Base.java

package Base;

class Base{

protected void amethod(){

System.out.println("amethod");

}

}

//Class1.java

package Class1;

public class Class1 extends Base{

public static void main(String argv[]){

Base b = new Base();

b.amethod();

}

}

A. Compile Error: Methods in Base not found

B. Compile Error: Unable to access protected method in base class

C. Compilation followed by the output "amethod"

D. Compile error: Class1 can not find class Base

9.In which of the following ways can items be added to a collection implemented by java.util.ArrayList?

I .Items can be inserted at the beginning of the collection.

II .Items can be inserted between two existing items in the collection.

III .Items can be appended to the end of the collection.

A. I, II, and III

B. I and III only

C. I only

D. III only

10. Assuming any exception handling has been set up, which of the following will create an instance of the RandomAccessFile class

A. RandomAccessFile raf=

new RandomAccessFile("myfile.txt","rw");

B. RandomAccessFile raf=new RandomAccessFile( new

DataInputStream());

C. RandomAccessFile raf=new RandomAccessFile("myfile.txt");

D. RandomAccessFile raf=new RandomAccessFile(

相关文档
最新文档