SCJP題庫第090題
11. interface DeclareStuff{
12. public static final int EASY = 3;
13. void doStuff(int t);}
14. public class TestDeclare implements DeclareStuff{
15. public static void main(String[] args){
16. int x = 5;
17. new TestDeclare().doStuff(++x);
18. }
19. void doStuff(int s){
20. s += EASY + ++s;
21. System.out.println("s " + s);
22. }
23. }
What is the result?
A. s 14
B. s 16
C. s 10
D. Compilation fails.
E. An exception is thrown at runtime.
Ans: D
解說:
在DeclareStuff介面中宣告的doStuff方法存取屬性是public(在介面的方法存取屬性是public的)
TestDeclare要覆載doStuff方法,必須滿足overriding規則,19行需改為public void doStuff(int s)
Comments