文档库

最新最全的文档下载
当前位置:文档库 > java单选题题目

java单选题题目

1. The name of a Java source file (d)

(d) must be the same as the class it defines, respecting case

2. Which method must exist in every Java application? (a)

(a) main

1. Given the following code, how many tokens will be output? (b)

StringTokenizer st = new StringTokenizer("this is a test");

while (st.hasMoreTokens()) {

stdOut.println(st.nextToken() );

}

(b) 4

2. Classes from which of the following packages are implicitly imported into every Java program? 答案:(d)

(d) http://www.wendangku.net/doc/680397e281c758f5f61f67da.htmlng

3. What is the name of the wrapper class for the type int? (d)

(d) Integer

4. Classes from which of the following packages are implicitly imported into every Java program?

(c)

(c) http://www.wendangku.net/doc/680397e281c758f5f61f67da.htmlng

5. The term wrapper classes refers to (a)

(a) a collection of Java classes that "wrap" Java primitive types

6. What will be output caused by the execution of the following Java program segment? (c) String name = "Elvis";

System.out.print(name + "was here");

(c) Elviswas here

1. What will be output when the following Java program segment is executed? (c)

int x = 5;

int y = 2;

System.out.println(x + y);

(c) 7

2. A difference between the methods print and println of the class java.io.PrintWriter is that (a)

(a) println appends a new line to the end of its output, but print does not

3. Consider the following Java program segment. (c)

int x = 5;

int y = 2;

System.out.println(x + "1" + y);

Which of the following statements is true about the program segment?

(c) The output caused by the code will be 512.

1. All Java exception classes are derived from the class (a)

(a) http://www.wendangku.net/doc/680397e281c758f5f61f67da.htmlng.Throwable

2. In Java, exceptions that are not handled are passed up the (b)

(b) call stack

3. What is the right way to handle abnormalities in input on Java? (d)

(d) By handling these problems by providing exception handlers

4. Consider the following Java program segment.

import java.io.*;

public class SomeClass{

public void x() {

throw new RuntimeException("Exception from x");

}

public void y(){

throw new IOException("Exception from y");

}

}

Which of the following is true concerning the definitions for the methods x and y? (a)

(a) x has a legal definition, but y has an illegal definition.

1. Which of the following statements is true of the conventions outlined by Sun Microsystems in the document entitled Code Conventions for the Java Programming Language? (d)

They define a standard interface definition language that must be used for all Java classes.

They provide recommendations intended to make source code easier to read and understand. They describe one mechanism for network communication between Java and C++ programs. (d) II only

Feedback: See section 1.1.6, subsection "CodeConvTOC" and section 1.1, subsection "Why Have Code Conventions," in the course notes.

2. According to the Java code conventions, files that contain Java source code have the suffix _____, and compiled bytecode files have the suffix _____. (d)

(d) .java, .class

Feedback: See section 1.1.6, subsection "CodeConvTOC" and section 2.1, subsection "File Suffixes," in the course notes.

3. According to the document entitled Code Conventions for the Java Programming Language, file suffixes used by Java software include which of the following? (b)

.obj

.class

.h

(b) II only

1. Which of the following patterns of characters opens a Javadoc comment block? (b)

(b) /**

1. After a typical debugger encounters a breakpoint, the programmer using the debugger may perform which of the following actions? (a)

Examine the values of variables in the halted program

Execute the current line

Resume execution of the halted program

(a) I, II, and III

2. In a typical source-code debugger, a programmer can set a _____ to cause a program to stop executing at a particular line of code. (c)

(c) breakpoint

3. A stack trace is (b)

(b) a sequence of method calls

4. A tool that allows programmers to execute lines of a program one line at a time in order to help locate the source of a program's errors is known as a(n) (b)

(b) debugger

1.According to Javadoc convention, the first sentence of each Javadoc comment should be (c) (c) a summary sentence of the declared entry

Feedback: See http://www.wendangku.net/doc/680397e281c758f5f61f67da.html/j2se/javadoc/writingdoccomments/index.html#format for more information.

1. In a UML class diagram's representation of a class, the top, middle, and lower rectangular compartments respectively describe the _____ of the class. (c)

(c) name, attributes, and methods

2. UML class diagrams can describe which of the following? (b)

The internal structure of classes

Relationships between classes

(b) I and II

1. Consider the following UML class diagram.

java单选题题目

According to the diagram, instances of the class named _____ have references to instances of the class named _____. (a)

(a) A, B

2. Consider the following UML class diagram.

java单选题题目

According to the diagram, which of the following statements is true? (a)

(a) ClassA is composed of one instance of ClassB and one or more instances of ClassC.

3. A binary association is said to exist between two classes when (a)

(a) an object of one class requires an object of the other class

4. The multiplicity of an association between two classes indicates the number of (a)

(a) instances of one class that can be associated with an instance of the other class

5. Which of the following is true about association and aggregation in UML class diagrams? (c)

(c) Aggregation is a special form of association.

1. A collection typically models a _____ relationship. (b)

(b) one-to-many

2. Consider the following UML class diagram. (c)

java单选题题目

The diagram describes a

(c) self-containing class

3. Consider the class described by the following diagram:

java单选题题目

If the class represents an employee and the boss attribute refers to the employee's boss, which of the following statements is (are) true? (c)

Many employees can have the same boss.

One employee can have many bosses.

(c) I only

4. Consider the following UML class diagram.

java单选题题目

Which of the following is (are) true about the system described by the diagram? (d)

An instance of Picture can contain a collection of instances of the class Shape.

An instance of Shape can contain a collection of instances of the class Picture.

(d) I only

5. If a class has an association with itself, then the class contains (b)

(b) an attribute that references an object of the same class

1. An object model describes which of the following? (c)

Attributes of classes

Methods of classes

Relationships between classes

(c) I, II, and III

2. In an object model, the data that an object is responsible for maintaining are represented by (b)

(b) attributes

1. A relationship that exists between two specific instances of an object is known as a(n) (b)

(b) link

Feedback: See Chapter 5, page 114, in the course textbook.

2. The static model of a software system typically includes which of the following? (b) Attributes of classes

Actions that occur between classes

Structural relationships between classes

(b) I and III only

Feedback: See Chapter 10, page 213, in the course textbook.

3. Consider the following UML class diagram.

According to the diagram, which of the following statements is (are) true? (c)

java单选题题目

ClassB is a specialization of ClassA.

ClassA is a generalization of ClassC.

ClassC is involved in a self-containment loop.

(c) I, II, and III

4. When using noun-phrase analysis to model a software system, which of the following should typically be eliminated from the list of potential classes? (a)

References to the software system itself

Nouns that imply roles between objects

Synonyms to other nouns in the list

(a) I, II, and III

Feedback: See Chapter 10, page 216-219, in the course textbook.

1. The term class variable is a synonym for (c)

(c) a static data field

1. Which is the Java keyword used to denote a class method? (c)

(c) static

2. Which of the following statements about class variables in Java is not true? (c)

(c) All objects have their own copy of the class variable defined in the instantiated class.

3. Which of the following categorizations can be applied to both the data fields and the methods in

a Java class? (a)

(a) static and non-static

1. What is used to indicate that a method does not return a value? (c)

(c) the keyword void

Feedback: See chapter 4 of the text.

2. The return type for a method that returns nothing to its caller is (c)

(c) void

Feedback: See chapter 4 of the text.

3. If a class contains a constructor, that constructor will be invoked (c)

(c) each time an object of that class is instantiated

Feedback: See chapter 4 of the text.

4. If the method int sum(int a, int b) is defined in a Java class C, which of the following methods cannot coexist as a different method in class C? (b)

(b) int sum(int x, int y)

Feedback: See chapter 5 of the text.

5. From within a child class, its parent class is referred to via the keyword (d)

(d) super

Feedback: See chapter 5 of the text.

6. When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be (a)

(a) overridden

Feedback: See chapter 5 of the text.

7. Consider the following Java class definitions.

public class Object1 {

protected String d(){

return "Hi";

}

}

public class Object2 extends Object1 {

protected String d(){

return super.d();

}

}

Which of the following statements is (are) true regarding the definitions? (d)

Class Object2 inherits from class Object1.

Class Object2 overrides method d.

Method d returns equivalent results when executed from either class.

(d) I, II, and III

Feedback: See chapters 5 and 13 of the text.

8. Consider the following Java program segment.

import java.io.*;

public class Test {

public Test( ) {

System.out.println("default");

}

public Test( int i ) {

System.out.println("non-default");

}

public static void main(String[] args) {

Test t = new Test(2);

}

}

Which of the following will be output during execution of the program segment? (a)

(a) The line of text "non-default"

Feedback: See chapter 13 of the text.

9. Which of the following statements about constructors in Java is true? (b)

(b) A class can define more than one constructor.

Feedback: See chapter 13 of the text.

10. Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass? (c)

(c) private

Feedback: See chapter 13 of the text.

1. Consider the following Java program segment.

int[] arr;

arr = new int[3];

arr[2]=19;

arr[1]=17;

arr[0]=15;

Which of the following Java statements is syntactically correct and semantically identical to the program segment? (b)

(b) int[] arr= {15, 17, 19};

2. Consider the Java program below.

public class Arr{

public static void main(String[] args) {

int[] a = {1, 2, 3};

System.out.println(a[1]);

System.out.println(a[3]);

}

}

Which of the following is true about the result of executing the program? (c)

(c) The number 2 is printed and a run-time exception terminates execution.

3. If the length of a particular array is the value of LIMIT, what is the index of the last item in that array? (d)

(d) LIMIT - 1

4. Legal Java statements to initialize an array reference include which of the following? (b)

int[] aobj = {0, 1, 2};

int[4] aobj = {0, 1, 2};

int[] aobj = new int[3];

(b) I and III only

5. A Java array that contains n components will be indexed from _____ through _____. (b)

(b) 0, n-1

6. Consider the following Java program segment.

String[] str = {"Three","Two","One"};

for (int i = 0; i < str.length; ++i) {

System.out.println(str[i]+"/");

}

What will be output upon execution of the program segment? (d)

(d) Three/Two/One/

7. Regarding the following declaration, what is the index of the element containing 45? (d)

int[] numbers = {-1, 45, 6, 132};

(d) 1

1. Consider the following method call, where c is an instance of the class java.util.ArrayList.

c.size();

This method call returns the number of (c)

(c) elements in the ArrayList represented by c

2. An object that contains methods that traverse a collection linearly from start to finish is known as a(n) (a)

(a) iterator

3. Which of the following statements is not true of the class java.util.ArrayList? (b)

(b) Once an object is inserted into an instance of ArrayList, it can never be removed.

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

Items can be inserted at the beginning of the collection.

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

Items can be appended to the end of the collection.

(b) I, II, and III

5. Which of the following methods is (are) provided by java.util.Iterator? (d)

next, which causes an iterator to return the next item in its iteration

remove, which can remove an item from a collection associated with an iterator

(d) I and II

6. The class java.util.ArrayList implements a collection that (c)

(c) can grow to accommodate new items

1. Which of the following statements is (are) true about any abstract method in Java? (b)

It contains no definition.

It cannot be declared public.

(b) I only

2. Which of the following statements is (are) true in Java? (b)

Classes that contain abstract methods must be declared abstract.

Classes that contain protected methods must be declared abstract.

(b) I only

3. The subclass of an abstract class must (c)

(c) be abstract or implement all of the parent's abstract methods

1. Which of the following statements about Java classes is (are) accurate? (c)

A class may have only one parent.

Two or more classes may share a parent.

(c) I and II

2. Consider the following Java program fragment.

public void drive(Vehicle v) {

...

}

...

drive(obj);

The method call drive(obj) is valid if obj is which of the following? (a)

A descendent of class Vehicle

An ancestor of class Vehicle

An object of class Vehicle

(a) I and III only

1. Which of the following statements is (are) true about interfaces in Java? (d)

Interfaces can extend other interfaces.

Interfaces can contain data fields.

(d) I and II

2. Which of the following statements is (are) true in Java? (d)

An abstract class may contain data fields.

Interfaces may contain data fields.

(d) I and II

3. Which of the following statements is (are) true about inheritance in Java? (c)

A class can extend more than one abstract class.

A class can implement more than one interface.

(c) II only

4. Which of the following statements is (are) true about all data fields in an interface in Java? (c) They are implicitly public.

They are implicitly final.

They are implicitly static.

(c) I, II, and III

5. Which is the Java keyword that denotes the use of an interface? (d)

(d) implements

6. Which of the following statements is (are) true in Java? (b)

All of the methods in an abstract class must be abstract.

All of the methods in an interface must be abstract.

(b) II only

7. In Java, all methods in an interface must be _____ and _____. (b)

(b) public, abstract

8. Data fields in an interface implicitly have _____ access in Java. (a)

(a) public

1. A design pattern is typically used to (c)

(c) describe a practical solution to a common design problem

1. Consider the following definition of a Java class.

public class C {

private static C instance = null;

private C() {

}

public static C getInstance() {

if (instance == null) {

instance = new C();

}

return C;

}

}

This class is an example of the design pattern (d)

(d) Singleton

2. The constructor of a class that adheres to the Singleton design pattern must have _____ visibility. (a)

(a) private

1. In which of the following design patterns is a family of algorithms encapsulated into individual but interchangeable classes? (a)

(a) Strategy

2. The Strategy design pattern is likely to be useful when implementing which of the following?(a) An application that offers several alternate sorting algorithms

A simple class to store the address of an organization of which only one instance can be instantiated

(a) I only

1. Consider the following Java program segment. (a)

PrintWriter fileOut = new PrintWriter(

new FileWriter("output.txt"));

If the file output.txt already exists, which of the following events will occur when the program segment is executed?

(a) The existing contents of output.txt will be erased.

2. If a file opened for reading does not exist, which of the following events will occur in Java? (a)

(a) A FileNotFoundException will be raised.

1. (1)The model part of the Model-View-Controller (MVC) paradigm embodies the (a)

(a) abstract domain knowledge of an application

(2)The view part of the Model-View-Controller (MVC) paradigm is the (b)

(b) way in which the abstract domain knowledge of an application is presented to the user

Feedback: See Chapter 16, page 474, in the course textbook.

2. Which of the following is true regarding the controller part in the Model-View-Controller (MVC) paradigm? (a)

(a) The controller is the automatic mechanism by which the user interface is displayed and by which events are communicated between the model and the view.

Feedback: See Chapter 16, page 475, in the course textbook.

3. In Java, the default layout manager for a JPanel component is (c)

(c) FlowLayout

Feedback: See Chapter 16, page 494, in the course textbook.

4. What is the number of regions into which the BorderLayout in Java subdivides a container? (a)

(a) 5

Feedback: See Chapter 16, page 494, in the course textbook.

5. Which of the following is (are) true regarding event handling in Java? (a)

When a GUI component is created, the component automatically has the ability to generate events during user interaction.

Each Listener object must be registered with the specific component object or objects for which the Listener object is to respond.

(a) I and II

Feedback: See Chapter 16, page 523, in the course textbook.

6. Which of the following is a Java event that is generated when a JButton component is pressed? 答案:(b)

(b) ActionEvent

Feedback: See Chapter 16, page 525, in the course textbook.

7. The ListSelectionEvent class and ListSelectionListener interface are available in the _____ package of Java. (b)

(b) javax.swing.event

Feedback: See Chapter 16, page 525, in the course textbook.

8. Which of the following is a Java event that is generated when the close button on a JFrame component is pressed? (b)

(b) WindowEvent

Feedback: See Chapter 16, page 534, in the course textbook.

9. In Java, what is the signature of the method in the WindowListener interface where code is to be added to end a program when the close button is pressed? (d)

(d) void windowClosing (WindowEvent we)

Feedback: See Chapter 16, page 537, in the course textbook.

10. What is the signature of the method specified in the Java ListSelectionListener interface? (b)

(b) void valueChanged (ListSelectionEvent lse)

Feedback: See Chapter 16, page 540, in the course textbook.

Given the following code, what value will be output by the last statement?

StringTokenizer st = new StringTokenizer("this is,a,test of tokens", ",");

String s;

int count = 0;

while (st.hasMoreTokens())

{ s = st.nextToken();

++count;

}

stdOut.println(count);

正确答案: C. 3

The name of a Java source file

正确答案: A. must be the same as the class it defines, respecting case

Which of the following statements is (are) true about the use of an asterisk (*) in a Java import statement?

It does not incur run-time overhead.

It can be used to import multiple packages with a single statement.

It can be used to import multiple classes with a single statement.

正确答案: B. 1 and 3 only

Consider the following Java program segment.

int x = 5; int y = 2; System.out.println(x + "1" + y);

Which of the following statements is true about the program segment?

正确答案: A. The output caused by the code will be 512.

What is the right way to handle abnormalities in input on Java?

正确答案: C. By handling these problems by providing exception handlers

The term wrapper classes refers to

正确答案: A. a collection of Java classes that "wrap" Java primitive types

From within a child class, its parent class is referred to via the keyword

正确答案: C. super

What is used to indicate that a method does not return a value?

正确答案: B. the keyword void

Which of the following statements about constructors in Java is true?

正确答案: D. A class can define more than one constructor.

When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be

正确答案: A. overridden

If a class contains a constructor, that constructor will be invoked

正确答案: B. each time an object of that class is instantiated

Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass?

正确答案: C. private

Consider the following Java class definitions.

public class Object1 {

protected String d()

{

return "Hi";

}

}

public class Object2 extends Object1

{

protected String d()

{

return super.d();

}

}

Which of the following statements is (are) true regarding the definitions?

Class Object2 inherits from class Object1.

Class Object2 overrides method d.

Method d returns equivalent results when executed from either class.

正确答案: C. I, II, and III

When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be

正确答案: A. overridden

If the method int sum(int a, int b) is defined in a Java class C, which of the following methods cannot coexist as a different method in class C?

正确答案: C. int sum(int x, int y)

import java.io.*;

public class Test {

public Test( ) {

System.out.println("default");

}

public Test( int i )

{

System.out.println("non-default");

}

public static void main(String[] args) {

Test t = new Test(2);

}

}

Which of the following will be output during execution of the program segment?

正确答案: C. The line of text "non-default"

Consider the Java program below.

public class Arr{

public static void main(String[] args)

{

int[] a = {1, 2, 3};

System.out.println(a[1]);

System.out.println(a[3]);

}

}

Which of the following is true about the result of executing the program?

正确答案: C. The number 2 is printed and a run-time exception terminates execution.

Which of the following methods is (are) provided by java.util.Iterator?

next, which causes an iterator to return the next item in its iteration

remove, which can remove an item from a collection associated with an iterator

正确答案: C. I and II

Which of the following statements is not true of the class java.util.ArrayList?

正确答案:C. Once an object is inserted into an instance of ArrayList, it can never be removed.

Regarding the following declaration, what is the index of the element containing 45?

int[] numbers = {-1, 45, 6, 132};

正确答案: D. 1

String[] str = {"Three","Two","One"};

for (int i = 0; i < str.length; ++i)

{ System.out.println(str[i]+"/"); }

What will be output upon execution of the program segment?

正确答案: C. Three/Two/One/

Consider the following method call, where c is an instance of the class java.util.ArrayList.

c.size();

This method call returns the number of

正确答案: C. elements in the ArrayList represented by c

Consider the following Java program segment.

int[] arr; arr = new int[3]; arr[2]=19; arr[1]=17; arr[0]=15;

Which of the following Java statements is syntactically correct and semantically identical to the program segment?

正确答案: D. int[] arr= {15, 17, 19};

If the length of a particular array is the value of LIMIT, what is the index of the last item in that array?

正确答案: A. LIMIT - 1

The class java.util.ArrayList implements a collection that

正确答案: D. can grow to accommodate new items

An object that contains methods that traverse a collection linearly from start to finish is known as a(n)

正确答案: C. iterator

UML class diagrams can describe which of the following?

1、The internal structure of classes

2、Relationships between classes

错误!未找到引用源。C. I and

II

In a UML class diagram's representation of a class, the top, middle, and lower rectangular compartments respectively describe the _____ of the class.

错 C. attributes, methods, and

误!

源。

methods

The multiplicity of an association between two classes indicates the number of

错误!未找到引用源。B. instances of one class that can be associated with an instance

of the other class

A collection typically models a _____ relationship.

误!

源。

C. one-to-many

A binary association is said to exist between two classes when

误!

源。

D. an object of one class requires an object of the other class

If a class has an association with itself, then the class contains

误!

B. an attribute that references an object of the same class

源。

When using noun-phrase analysis to model a software system, which of the following should typically be eliminated from the list of potential classes?

1、References to the software system itself

2、Nouns that imply roles between objects

3、Synonyms to other nouns in the list

C. I, II, and III

误!

源。

The static model of a software system typically includes which of the following?

1、Attributes of classes

2、Actions that occur between classes

3、Structural relationships between classes

C. I and III only

误!

源。

Which of the following is true about association and aggregation in UML class diagrams?

D. Aggregation is a special form of association.

误!

源。