2009年2月11日 星期三

第81題

Given:
1. interface DoStuff2{
2. float getRange(int low, int high);}
3.
4. interface DoMore {
5. float getAvg(int a, int b, int c);}
6.
7. abstract class DoAbstract implements DoStuff2, DoMore{}
8.
9. class DoStuff implements DoStuff2{
10. public float getRange(int x, int y){return 3.14f;}}
11.
12. interface DoAll extends DoMore{
13. float getAvg(int a, int b, int c, int d);}
What is the result?
A. The file will compile without error.
B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error.
D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.
F. Compilation fails. Only lines 7 and 13 contain errors.
G. Compilation fails. Lines 7, 12, and 13 contain errors.
答案:A
參考:7-5 抽象類別、7-6 介面
------------------------------------------------------------
7. abstract class DoAbstract implements DoStuff2, DoMore{} //抽象類別實做二個介面但不實做二個方法是沒有關係的

9. class DoStuff implements DoStuff2{
10. public float getRange(int x, int y){return 3.14f;}} //正常類別實做介面的話要把介面實做出來

12. interface DoAll extends DoMore{ //介面繼承介面是沒有問題的
13. float getAvg(int a, int b, int c, int d);} //不是實做第5行,由參數可知

沒有留言:

張貼留言