QUESTION 150
Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?
A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.
Answer: D
问题出在第24行,classC还没有new一个,就直接用函数getValue(),NullPointerException会被抛出
public ClassC classC;该行代码没有new出来ClassC,空指针异常;
QUESTION 151 Given:
static void test() throwsRuntimeException {
try {
System.out.print("test");
throw new RuntimeException();
}
catch (Exception ex) { System.out.print("exception"); }
}
public static voidmain(String[] args) {
try { test(); }
catch (RuntimeException ex) {System.out.print("runtime "); }
System.out.print("end");
}
What is the result?
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by mainat runtime.
Answer: D
QUESTION 152 Given:
public class Plant {
private String name;
public Plant(String name) {this.name = name; }
public String getName() { returnname; }
}
public class Tree extends Plant{
public void growFruit() { }
public void dropLeaves() { }
}
Which statement is true?
A. The code will compile withoutchanges.
B. The code will compile if publicTree() { Plant(); } is added to the Tree class.
C. The code will compile if publicPlant() { Tree(); } is added to the Plant class.
D. The code willcompile if public Plant() { this("fern"); } is added to the Plantclass.
E. The code will compile if publicPlant() { Plant("fern"); } is added to the Plant class.
Answer: D
Section: (none)
Plant需要一个无参默认构造函数,因为子类带一个参数的构造函数
QUESTION 153
Given:
class Line {
public static class Point {}
}
class Triangle {
// insert code here
}
Which code, inserted at line 15, createsan instance of the Point class defined in Line?
A. Point p = new Point();
B. Line.Point p = newLine.Point();
C. The Point class cannot beinstatiated at line 15.
D. Line l = new Line() ; l.Point p= new l.Point();
Answer: B
QUESTION 154 Given:
class Nav{
public enum Direction { NORTH,SOUTH, EAST, WEST }
}
public class Sprite{
// insert code here
}
Which code, inserted at line 14, allowsthe Sprite class to compile?
A. Direction d = NORTH;
B. Nav.Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;
Answer: D
Section: (none)
共同学习,写下你的评论
评论加载中...
作者其他优质文章