当前位置: 技术问答>java相关
SCJP考题一道???????
来源: 互联网 发布时间:2015-03-04
本文导语: Question 7: Given this class definitions: abstract class Transaction implements Runnable { } class Deposit extends Transaction { protected void process() { addAmount(); } void undo(int i) { System.out.println("Undo"); } } What will h...
Question 7: Given this class definitions:
abstract class Transaction implements Runnable { }
class Deposit extends Transaction {
protected void process() {
addAmount();
}
void undo(int i) {
System.out.println("Undo");
}
}
What will happen if we attempted to compile the code?
Select the one right answer.
a) This code will not compile because the parameter i is not used in undo().
b) This code will not compile because there is no main() method.
c) This code will not compile because Deposit must be an abstract class.
d) This code will not compile because Deposit is not declared public.
e) Everything will compile fine.
大家选哪个?请说明为什么?
abstract class Transaction implements Runnable { }
class Deposit extends Transaction {
protected void process() {
addAmount();
}
void undo(int i) {
System.out.println("Undo");
}
}
What will happen if we attempted to compile the code?
Select the one right answer.
a) This code will not compile because the parameter i is not used in undo().
b) This code will not compile because there is no main() method.
c) This code will not compile because Deposit must be an abstract class.
d) This code will not compile because Deposit is not declared public.
e) Everything will compile fine.
大家选哪个?请说明为什么?
|
因为在Transaction中没有定义run()方法,而扩展了Runnable接口,所以在类Deposit中也有一个abstract方法run(),所以类Deposit必须定义为abstract