1、定義介面
package test.intefaces; public interface TestIntefaceA { void testA(); void testB(); void testC(); }
2、定義抽象類實現介面:
package test.intefaces.impl; import test.intefaces.TestIntefaceA; public abstract class TestAbstractImplA implements TestIntefaceA { @Override public void testA() { } public void testNewD() { System.out.println("新追加的方法!"); } }
2-1:定義類繼承抽象類:
package test.intefaces.impl; import test.intefaces.TestIntefaceA; public class TestImplA1 extends TestAbstractImplA { @Override public void testA(){ // 父類抽(抽象類已經實現了該方法,可以重寫,也可以不重寫,不會出錯) }
// 必須要有 @Override public void testB() { // TODO Auto-generated method stub }
@Override public void testC() { // 必須要有 // TODO Auto-generated method stub } }
2-2:普通類繼承父類,實現介面
package test.intefaces.impl; public class TestImplA2 extends TestAbstractImplA { @Override public void testB() { // TODO Auto-generated method stub } @Override public void testC() { // TODO Auto-generated method stub } }
以上,好好學習一下!