华恩JAVA班长训第八十一天
由于今天导师找我开会关于毕业设计的事情,所以请假了一天,加上明天我有一个java全球认证的考试,所以我抓紧时间看题库和做模拟题。
其中的一部分题目如下:
QUESTION 27
Given that c is a reference to a valid java.io.Console object,
and:
11. String pw = c.readPassword("%s", "pw: ");
12. System.out.println("got " pw);
13. String name = c.readLine("%s", "name: ");
14. System.out.println(" got ", name);
If the user types fido when prompted for a password, and then
responds bob when prompted for a name,
what is the result?
A. pw: got fido name: bob got bob
B. pw: fido got fido name: bob got bob
C. pw: got fido name: bob got bob
D. pw: fido got fido name: bob got bob
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: E
Explanation/Reference:
The method println(String) in the type PrintStream is not
applicable for the arguments
(String, String)
QUESTION 28
Given:
11. String test = "This is a test";
12. String[] tokens = test.split("\s");
13. System.out.println(tokens.length);
What is the result?
A. 0
B. 1
C. 4
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: D
Explanation/Reference:
Invalid escape sequence (valid ones are \b \t \n \f \r " \' \\
)
QUESTION 29
Given:
import java.io.*;
class Animal {
Animal() {
System.out.print("a");
}
}
class Dog extends Animal implements Serializable {
Dog() {
System.out.print("d");
}
}
public class Beagle extends Dog {
}
If an instance of class Beagle is created, then Serialized, then
deSerialized, what is the result?
A. ad
B. ada
C. add
D. adad
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: B
Explanation/Reference:
QUESTION 30
Given:
11. double input = 314159.26;
12. NumberFormat nf =
NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here
Which code, inserted at line 14, sets the value of b to
314.159,26?
A. b = nf.parse( input );
B. b = nf.format( input );
C. b = nf.equals( input );
D. b = nf.parseObject( input );
Answer: B
Explanation/Reference:
QUESTION 31
A team of programmers is involved in reviewing a proposed design
for a new utility class.
After some discussion, they realize that the current design allows
other classes to access
methods in the utility class that should be accessible only to
methods within the utility class itself.
What design issue has the team discovered?
A. Tight coupling
B. Low cohesion
C. High cohesion
D. Loose coupling
E. Weak encapsulation
F. Strong encapsulation
Answer: E
Explanation/Reference:
QUESTION 32
Given a method that must ensure that its parameter is not
null:
11. public void someMethod(Object value) {
12. // check for null value
...
20. System.out.println(value.getClass());
21. }
What, inserted at line 12, is the appropriate way to handle a null
value?
A. assert value == null;
B. assert value != null, "value is null";
C. if (value == null) { throw new AssertionException("value is
null"); }
D. if (value == null) { throw new IllegalArgumentException("value
is null"); }
Answer: D
Explanation/Reference:
Exam H
QUESTION 1
Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args){
3. System.out.println(new Target().addOne());
4. }
5. }
Which change 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
Explanation/Reference:
QUESTION 2
Given:
class Animal {
public String noise() {
return "peep";
}
}
class Dog extends Animal {
public String noise() {
return "bark";
}
}
class Cat extends Animal {
public String noise() {
return "meow";
}
}
...
30. Animal animal = new Dog();
31. Cat cat = (Cat)animal;
32. System.out.println(cat.noise());
What is the result?
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: E