1. Which method must exist in every Java application?
(a) main (b) paint
(c) begin (d) init
2. Which of the following is the string concatenation operator in Java?
(a) + (b) ^
(c) & (d) ++
3. Which of the following statements is (are) true about the use of an asterisk (*)
in a Java import statement?
I.
II. III.
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.
(a) I and III only (b) III only (c) I only
(d) I, II, and III
4. A difference between the methods print and println of the class
java.io.PrintWriter is that
(a) print inserts a new line at the beginning of its output, but println does not
(b) println appends a new line to the end of its output, but print does not
not
(d) print appends a new line to the end of its output, but println does not
5. What will be output when the following Java program segment is executed?
(c) println inserts a new line at the beginning of its output, but print does
int x = 5;
int y = 2;
System.out.println(x + y);
(a) 7 (b) 5 2
(c) 5+2 (d) 52
6. What is the right way to handle abnormalities in input on Java?
(a) By handling these problems by providing exception handlers
(b) By writing while loops to guard against bad input
(c) By using the class FileFilter which gracefully filters out bad input data (d) By always specifying the throws clause in every method header where file I/O is performed
7. All Java exception classes are derived from the class
(a) java.lang.Throwable (b) java.lang.Error
(c) java.io.IOException
(d) java.lang.RuntimeException
8. According to Javadoc convention, the first sentence of each Javadoc
comment should be
(a) an @version tag
(b) the order of lines is not important
(c) an @author tag
(d) a summary sentence of the declared entry
9. According to the document entitled Code Conventions for the Java
Programming Language, file suffixes used by Java software include which of
the following?
I. .obj
II. III.
.class .h
(a) I and III only (b) II and III only
(c) I and II only (d) II only
10. A stack trace is
(a) a sequence of method calls
(b) only available through a typical debugger's step into feature (c) a fatal error that causes a typical debugger to terminate (d) a list of variables allocated on a program's stack 11.The name of a Java source file
选择一个答案
a. has no restrictions
b. must be the same as the class it defines, ignoring case
c. must use the extension .class
d. must be the same as the class it defines, respecting case
12.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选择一个答案
a. exception handler
b. stack trace c. scope
d. debugger
13.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?。
I They define a standard interface definition language that must be used for all Java classes.
II They provide recommendations intended to make source code easier to read and understand.
III They describe one mechanism for network communication between Java and C++ programs. 选择一个答案
a. II only
b. I, II, and III
c. I and III only
d. III only
Multiple-Choice Quiz 2
1. UML class diagrams can describe which of the following?
I. II.
The internal structure of classes Relationships between classes
(a) I and II (b) None
(c) II only (d) I only
2. In a UML class diagram's representation of a class, the top, middle, and lower
rectangular compartments respectively describe the _____ of the class.
(a) attributes, methods, and name (b) attributes, methods, and constants
(c) name, attributes, and methods (d) name, methods, and constants
3. A collection typically models a _____ relationship.
(a) one-to-one (b) zero-to-one
(c) many-to-many (d) one-to-many
4. A relationship that exists between two specific instances of an object is known
as a(n)
(a) aggregation (b) specialization
(c) association (d) link
5. Consider the following UML class diagram.
According to the diagram, which of the following statements is true?
(a) ClassA and ClassB each contain at least one reference to an instance of ClassC.
(b) ClassB and ClassC are both subclasses of ClassA.
(c) ClassA is composed of one instance of ClassB and one or more instances of ClassC.
(d) ClassB has a one-to-one association with ClassA and a one-to-many association with ClassC.
6. Consider the following UML class diagram.
The diagram describes a
(a) class without methods
(b) relationship between a subclass and a superclass
(c) one-to-one relationship (d) self-containing class
7. Which of the following is true about association and aggregation in UML class
diagrams?
(a) Association and aggregation have no meaningful relationship. (b) Association is a special form of aggregation.
(c) Association is the opposite of aggregation. (d) Aggregation is a special form of association.
8. Consider the following UML class diagram.
Which of the following is (are) true about the system described by the
diagram?
I. An instance of Picture can contain a collection of instances of the class Shape.
II. An instance of Shape can contain a collection of instances of the class Picture.
(a) None (b) I only
(c) II only (d) I and II
9. The static model of a software system typically includes which of the
following?
I.
II. III.
Attributes of classes
Actions that occur between classes Structural relationships between classes
(a) II and III only (b) I and III only
(c) I, II, and III (d) I and II only
10. An object model describes which of the following?
I.
II. III.
Attributes of classes Methods of classes
Relationships between classes
(a) I, II, and III (b) I and II only (c) II and III only (d) I and III only
11.Which of the following parts of an if-else-statement is optional? 选择一个答案
a. the else part
b. the condition
c. the if part
d. the parenthesis around the condition
12. Which of the following is the Java loop construct typically used when the range is clear?
选择一个答案
a. for-loop
b. switch-loop
c. while-loop
d. do-while-loop
13.The primitive floating-point types available in Java are _____ and _____. 选择一个答案
a. float , double
b. real, double
c. single , real
d. real , float
14.How many bytes are required to represent a Unicode character? 选择一个答案
a. One b. Three c. Four d. Two
15.How many lines of output will be produced by the following code fragment? for (int i = 0; i < 4; ++i) { for (int j = 1; j < 3 ; ++j) { stdOut.println(i + j); 选择一个答案
a. 6 b. 12
c. 8 d. 10
16.How many lines of output will be produced by the following code fragment?
for (int i = 0; i < 3; ++i) { for (int j = 0; j < i; ++j) { stdOut.println(i + j);
} }
选择一个答案
a. 6 b. 3 c. 4 d. 5
17.The term wrapper classes refers to 选择一个答案
a. a collection of Java classes that \"wrap\" Java primitive types
b. a collection of Java classes that contain other Java classes
c. the Java classes that contain at least two data fields
d. the Java classes that contain themselves
18.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);
选择一个答案
a. 3 b. 6 c. 1 d. 4
19.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 5 1 2.
b. The code will cause a compilation error.
c. The output caused by the code will be 8.
d. The output caused by the code will be 512.
20.In programming, a loop is generally used to achieve 选择一个答案
a. repetition
b. branching
c. selection
d. succession
21.What is the name of the wrapper class for the type int? 选择一个答案
a. integer b. INT c. Int
d. Integer
Multiple-Choice Quiz 3
1. Which of the following categorizations can be applied to both the data fields and the methods in a Java class?
(a) native and non-native (b) default and non-default
(c) static and non-static (d) abstract and non-abstract
2. 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) The line of text \"non-default\" (b) The line of text \"default\"
(c) The line of text \"non-default\" followed by the line of text \"default\" (d) The line of text \"default\" followed by the line of text \"non-default\"
3. The return type for a method that returns nothing to its caller is
(a) void (b) false
(c) not specified in the method definition (d) null
4. If a class contains a constructor, that constructor will be invoked
(a) each time an object of that class is instantiated
(b) once the first time an object of that class is instantiated
(c) each time an object of that class goes out of scope (d) once at the beginning of any program that uses that class
5. Which of the following statements about constructors in Java is true?
(a) A class must define at least one constructor. (b) A class can define more than one constructor.
(c) A constructor must be defined as public. (d) A constructor must be defined as static.
6. What is used to indicate that a method does not return a value?
(a) the keyword void
(b) the name of the class to which it belongs
(c) the omission of the return type (d) the keyword static
7. 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) hidden (b) overridden
(c) private (d) overloaded
8. Which is a Java access modifier used to designate that a particular data field
will not be inherited by a subclass?
(a) final (b) default
(c) protected (d) private
9. 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?
(a) int sum(float a, int b) (b) int sum(int x, float y)
(c) int sum(int x, int y) (d) float sum(int x, float y)
10. 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?
I. II. III.
Class Object2 inherits from class Object1. Class Object2 overrides method d.
Method d returns equivalent results when executed from either class.
(a) I and II only (b) I, II, and III
(c) III only (d) I and III only
Multiple-Choice Quiz 4
1. 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?
(a) The number 2 is printed and a run-time exception terminates execution. (b) The number 2 is printed and there is no abnormal termination.
(c) The number 1 is printed and there is no abnormal termination.
(d) The number 3 is printed and a run-time exception terminates execution.
2. Regarding the following declaration, what is the index of the element
containing 45?
(a) 2 (b) 0
int[] numbers = {-1, 45, 6, 132};
(c) 1 (d) 45
3. A Java array that contains n components will be indexed from _____ through
_____.
(a) 0, n-1 (b) 1, n
(c) 0, n (d) 1, n-1
4. Consider the following Java program segment.
String[] str = {\"Three\
for (int i = 0; i < str.length; ++i) { System.out.println(str[i]+\"/\"); }
What will be output upon execution of the program segment?
(a) Three/Two/One/ (b) One/Two/Three/
(c) One,Two,Three (d) Three,Two,One
5. Legal Java statements to initialize an array reference include which of the
following?
I.
II. III.
int[] aobj = {0, 1, 2};
int[4] aobj = {0, 1, 2}; int[] aobj = new int[3];
(a) I and II only (b) I only
(c) III only (d) I and III only
6. An object that contains methods that traverse a vector linearly from start to
finish is known as a(n)
(a) loop (b) iterator
(c) int
(d) Exception
7. The class java.util.Vector implements a collection that
(a) cannot be accessed using an integer index
(b) can only store instances of the class java.lang.String
(c) can grow to accommodate new items
(d) can only store primitive variables such as int or boolean
8. Consider the following method call, where v is an instance of the class
java.util.Vector.
v.size();
This method call returns the number of
(a) bytes used by v
(b) times that the method v.add has been called
(c) Vector objects that have been instantiated (d) elements in the vector represented by v
9. In which of the following ways can items be added to a collection
implemented by java.util.Vector?
I. II. III.
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.
(a) III only (b) I and III only
(c) I, II, and III (d) I only
10. Array elements may only be retrieved using _____, whereas vector elements
may also be retrieved using _____.
(a) indexes, iterators (b) iterators, indexes
(c) names, indexes (d) indexes, names
Multiple-Choice Quiz 5
1. The subclass of an abstract class must
(a) be abstract and implement all of the parent's abstract methods (b) implement all of the parent's abstract methods
(c) be abstract
(d) be abstract or implement all of the parent's abstract methods
2. Which of the following statements is (are) true about any abstract method in
Java?
I. II.
It contains no definition. It cannot be declared public.
(a) None (b) II only
(c) I and II (d) I only
3. Which of the following statements about Java classes is (are) accurate?
I.
II.
A class may have only one parent.
Two or more classes may share a parent.
(a) I and II (b) None
(c) I only (d) II only
4. Which of the following statements is (are) true in Java?
I.
II.
All of the methods in an abstract class must be abstract.
All of the methods in an interface must be abstract.
(a) None (b) I and II
(c) I only (d) II only
5. Which of the following statements is (are) true about inheritance in Java?
I.
II.
A class can extend more than one abstract class.
A class can implement more than one interface.
(a) II only (b) None
(c) I and II (d) I only
6. Which of the following statements is (are) true in Java?
I.
II.
An abstract class may contain data fields.
Interfaces may contain data fields.
(a) I only (b) II only
(c) None (d) I and II
7. Which of the following statements is (are) true about interfaces in Java?
I. II.
Interfaces can extend other interfaces. Interfaces can contain data fields.
(a) I only (b) II only
(c) None (d) I and II
8. A design pattern is typically used to
(a) ensure that code executes at optimal speed during runtime (b) reduce the number of classes in the design of a program
(c) allow the use of object-orientated concepts in a language that is not object-oriented
(d) describe a practical solution to a common design problem
9. 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
(a) Singleton (b) Strategy
(c) Adapter (d) Decorator
10. The Strategy design pattern is likely to be useful when implementing which
of the following?
I.
II.
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) II only
(b) None (c) I and II (d) I only
Multiple-Choice Quiz 6
1. If a file opened for reading does not exist, which of the following events will occur in Java?
(a) A new file will be created. (b) A run-time error will occur.
(c) A NullPointerException will be raised. (d) A FileNotFoundException will be raised.
2. Which of the following is true regarding the controller part in the
Model-View-Controller (MVC) paradigm?
(a) The controller is the list of abstract classes in an application. (b) The controller is the abstract domain knowledge of an application. (c) The controller is the way in which the abstract domain knowledge of an application is presented to the user.
(d) 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.
3. In Java, the default layout manager for a JFrame component is
(a) GridLayout
(b) GridBagLayout (c) FlowLayout (d) BorderLayout
4. Which of the following is (are) true regarding containers and components in
the context of java GUI?
I.
II. III.
A container can be added to a component.
A component can be added to a container. A container can be added to another container.
(a) I and II only (b) II and III only
(c) I and III only (d) I, II, and III
5. The model part of the Model-View-Controller (MVC) paradigm embodies the
(a) way in which the abstract domain knowledge of an application is presented to the user
(b) list of abstract classes in an application
(c) abstract domain knowledge of an application
(d) automatic mechanism by which the user interface is displayed and by which events are communicated between the view and the controller 6. What is the signature of the method specified in the Java ActionListener
interface?
(a) void actionPerformed (ActionListener al) (b) void actionListener (ActionEvent ae)
(c) void actionPerformed (ActionEvent ae) (d) void actionEvent (ActionPerformed ap)
7. 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?
(a) void windowAdapter (WindowEvent we) (b) void windowDeactivated (WindowEvent we)
(c) void windowClosing (WindowEvent we) (d) void windowClosed (WindowEvent we)
8. Which of the following is a Java event that is generated when the close button
on a JFrame component is pressed?
(a) CloseEvent (b) DisposeEvent
(c) WindowEvent (d) ExitEvent
9. Which of the following is (are) true regarding event handling in Java?
I. When a GUI component is created, the component automatically has
the ability to generate events during user interaction. II.
Each Listener object must be registered with the specific component object or objects for which the Listener object is to respond.
(a) None (b) II only
(c) I only (d) I and II
10. Which of the following is a Java event that is generated when a JButton
component is pressed?
(a) ButtonEvent (b) ActionEvent
(c) ClickEvent (d) WindowEvent
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- obuygou.com 版权所有 赣ICP备2024042798号-5
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务