2024年6月12日发(作者:)
QUESTION 121
Given:
Which code, inserted at line 15, creates an instance of the Point class defined in Line?
A. Point p = new Point();
B. p = new ();
C. The Point class cannot be instatiated at line 15.
D. Line 1 = new Line() ; p = new ();
Answer: ( B )
静态内部类创建方法
非静态内部类的构造:
p = new Line().new Point();
参考大纲:面向对象
—
内部静态类
QUESTION 122
Given:
Which statement is true?
A. The code will compile without changes.
B. The code will compile if public Tree() { Plant(); } is added to the Tree class.
C. The code will compile if public Plant() { Tree(); } is added to the Plant class.
D. The code will compile if public Plant() { this("fern"); } is added to the Plant class.
E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.
Answer: ( D )
子类默认调用父类无参构造函数,而Plant没有无参构造函数,因此须显示调用有参构造函数
参考大纲:面向对象
QUESTION 123
Given:
Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose
two.)
A. foreach( x ) 1n(z);
B. for( int z : x ) 1n(z);
C. while( xt() ) 1n( () )
D. for( int i=0; i < ; i++ ) n(x[i]);
Answer: ( B, D )
可变参数方法编译后变成数组参数方法,然后利用循环结构取出数组的值
参考大纲:流程控制和可变长度参数
QUESTION 124
Exhibit:
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.
Answer: ( C )
参考大纲:面向对象 — 复写
QUESTION 125
Place the lines in the correct order to complete the enum。
enum Element {
Answer: ( )
enum Element {
EARTH, WIND,
FIRE{
public String info(){return “Hot”;}
};
public String info(){return “element”;}
}
列举的内容之后要加上“;”
参考大纲:面向对象 — enum
QUESTION 126
Place the code elements in order so that the resulting Java source file will compile
correctly, resulting in a class called sBook.
Answer: ( )
package ;
import .*;
public class AddressBook{
ArrayList entries;
}
参考大纲:面向对象 — 语法基础
QUESTION 127
Which two classes correctly implement both the le and the
le interfaces? (Choose two.)
A. public class Session implements Runnable, Clonable {
public void run ();
public Object clone();
}
B. public class Session extends Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
C. public class Session implements Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
D. public abstract class Session implements Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
E. public class Session implements Runnable, implements Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
Answer: ( C, D )
A 错误 Session是具体类,方法必须实现
B 实现interface用implements
C 正确
D 正确
E 错误implements只能出现一次
参考大纲:多线程
QUESTION 128
Given:
Which statement is true?
A. 420 is the output
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.
Answer: ( A )
参考大纲:面向对象
QUESTION 129
Given:
What is the result?
A. foofoofoofoofoo
B. foobarfoobarbar
C. foobarfoofoofoo
D. foobarfoobarfoo
E. barbarbarbarbar
F. foofoofoobarbar
G. foofoofoobarfoo
Answer: ( D )
参考大纲:面向对象—属性的重载和遮蔽,该题中子类遮蔽了父类的属性
QUESTION 130
Which two statements are true about has-a and is-a relationships? (Choose two.)
A. Inheritance represents an is-a relationship.
B. Inheritance represents an has-a relationship.
C. Interfaces must be use when creating a has-a relationship.
D. Instance variables can be used when creating a has-a relationship.
Answer: ( A, D )
参考大纲:面向对象
QUESTION 131 --------
Given:
Which statement is true about the class of an object that can reference the variable base?
A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
Answer: ( C )
参考大纲:面向对象
QUESTION 132
Given:
Place the names "A" and "B" in the following output.
Answer: ( )
参考大纲:面向对象 class B has name A
QUESTION 133
Given:
What is the result?
A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then d() invokes the version of bMethod()
defined in line 5.
E. If you define D e = (D)(new E()), then d() invokes the version of bMethod()
defined in line 5.
F. If you define D e = (D)(new E()), then d() invokes the version of bMethod()
defined in line 9.
Answer: ( F ) E类的对象调用(),因为E类体里有这个方法就遮蔽了父类的方法
参考大纲:面向对象
QUESTION 134
Which two statements are true? (Choose two.)
A. An encapsulation, public class promotes re-use.
B. Classes that share the same interface are always tightly encapsulated.
C. An encapsulated class allows subclasses to overload methods, but does NOT allow
overriding methods.
D. An encapsulated class allows programmer to change an implementation without
affecting outside code.
Answer: ( A, D)
参考大纲:面向对象
QUESTION 135 -----BT
Place the Relations on their corresponding Implementation Structures.
Note: Not all Implementation Structres will be used.
Answer: ( )
参考大纲:面向对象
QUESTION 136
Given:
And:
What is the result?
A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.
Answer: ( C )
19行应改为this(),应该放在第一行;
参考大纲:面向对象
QUESTION 137 --
Given:
A. Change line 2 to: public int a;
B. Change line 2 to: protected int a;
C. Change line 13 to: public Sub() {this(5);}
D. Change line 13 to: public Sub() {super(5);}
E. Change line 13 to: public Sub() {super(a);}
Which two, independently, will allow Sub to compile? (Choose two.)
Answer: ( C, D )
参考大纲:面向对象
QUESTION 138 --
Given:
What is the result when the programmer attempts to compile the code and run it with the command:
java Converter 12 ?
A. It is true that j == i.
B. It is false that j == i.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.
Answer: ( D )
参考大纲:语言基础
QUESTION 139
Given:
What is the output?
A. 42
B. 420
C. 462
D. 42042
E. Compilation fails
F. An exception is thrown at runtime.
Answer: ( D )
参考大纲:语言基础
QUESTION 140 -- BT
Assuming that the serializeBanana2() and the deserializeBanana2() methods will
correctly use Java serialization and given:
What is the result?
A. Compilation fails
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime
Answer: ( D )
因为父类Food未实现serializable接口,反序列化时将调用Food的构造函数.见工程执行结果
参考大纲:IO操作 — 序列化机制
QUESTION 141
Given:
What is the result?
A. a b c
B. 1 2 3
C. a1b2c3
D. a1 b2 c3
E. Compilation fails
F. The code runs with no output.
G. An exception is thrown at runtime.
Answer: ( A )
参考大纲:实用API
QUESTION 142
Given:
What is the result?
A. Compilation fails
B. After line 15, the value of age is 5.
C. After line 15, the value of age is 3.
D. An exception is thrown at runtime.
Answer: ( D )
抛出ismatchException异常
正确读取方法:
();
t();
olean();
t();
参考大纲:实用API — Scanner简易I/O工具
QUESTION 143
Given a valid DateFormat object named df, and
What updates d's value with the date represented by ds?
A. A
B. B
C. C
D. D
Answer: ( C )
DateFormat类的parse(String s) 会抛ParseException
异常.
参考大纲:实用API — DataFormat
QUESTION 144
Place the Fragments into the program, so that the program will get lines from a text file, display them,
and then close all the resources.
Answer: ( )
参考大纲:IO操作
QUESTION 145
Given:
And:
Which changes can you make to Target without affecting Client?
A. Line 4 of class Target can be changed to return i++;
B. Line 2 of class Target can be changed to private int i =1;
C. Line 3 of class Target can be changed to private int addOne(){
D. Line 2 of class Target can be changed to private Integer i = 0;
Answer: ( D )
A: return ++i; 和return i++; 不一样.
参考大纲:实用API
QUESTION 146
Given:
Which statement is true?
A. Compilation will succeed if A extends B.
B. Compilation will succeed if B extends A.
C. Compilation will always fail because of an error in line7.
D. Compilation will always fail because of an error in line8.
Answer: ( B )
参考大纲:面向对象 — 重写
QUESTION 147
Given:
What is the result?
A. Compilation fails.
B. Cannot add Toppings
C. The code runs with no output.
D. A NullPointerException is thrown in Line 4.
Answer: ( A )
final方法不能重写
参考大纲:面向对象
QUESTION 148
Insert six modifiers into the code such that it meets all of these requirements:
Answer: ( )
2,4,8,9行符合条件一; 3行符合条件二; 5行符合条件三.
参考大纲:语言基础 — 存取权限
QUESTION 149
Given:
And:
What is the result?
A. The code runs with no output.
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 23.
F. Compilation fails because of an error in line 25.
Answer: ( F )
a 对象没有y( )方法
参考大纲:面向对象
QUESTION 150
A programmer needs to create a logging method that can accept an arbitrary
number of arguments. For example, it may be called in these ways:
Which declaration satisfies this requirement?
A. public void logIt(String * msgs)
B. public void logIt(String [] msgs)
C. public void msgs)
D. public void logIt(String msg1, String msg2, String msg3)
Answer: ( C )
参考大纲:面向对象 可变参数
QUESTION 151----------------------------------
Exhibit:
What is the result?
A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.
Answer: ( D )
父类没有无参构造函数
参考大纲:面向对象
QUESTION 152
Given:


发布评论