实现VS扩展:何时使用?有什么关系呢?请用通俗易懂的语言解释或链接到某篇文章。
3 回答
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
extends
implements
public interface ExampleInterface { public void doAction(); public String doThis(int number); } public class sub implements ExampleInterface { public void doAction() { //specify what must happen } public String doThis(int number) { //specfiy what must happen } }
public class SuperClass { public int getNb() { //specify what must happen return 1; } public int getNb2() { //specify what must happen return 2; } } public class SubClass extends SuperClass { //you can override the implementation @Override public int getNb2() { return 3; } }
Subclass s = new SubClass(); s.getNb(); //returns 1 s.getNb2(); //returns 3 SuperClass sup = new SuperClass(); sup.getNb(); //returns 1 sup.getNb2(); //returns 2
呼如林
TA贡献1798条经验 获得超3个赞
interface
extend
implement
添加回答
举报
0/150
提交
取消