Given:
10. interface Data { public void load(); }
11. abstract class Info { public abstract void load(); }
Which class correctly uses the Data interface and Info class?
A. public class Employee extends Info implements Data {
public void load(){ /* do something */ }
}
B. public class Employee implements Info extends Data {
public void load(){ /* do something */ }
}
C. public class Employee extends Info implements Data
public void load(){ /* do something */ }
public void Info.load(){ /* do something */ }
}
D. public class Employee implements Info extends Data {
public void Data.load(){ /* do something */ }
public void load(){ /* do something */ }
}
E. public class Employee implements Info extends Data {
public void load(){ /* do something */ }
public void Info.load(){ /* do something */ }
F. public class Employee extends Info implements Data{
public void Data.load(){ /* do something */ }
public void Info.load(){ /* do something */ }
}
答案:A
參考:7-5 抽象類別、7-6 介面
--------------------------------------------------------
不管繼承抽象類別或實做介面,必須把裡面的抽象方法實做出來.
抽象類別(abstract) 用 extends, 介面(interface) 使用 implements 關鍵字.
沒有留言:
張貼留言