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 } }
以上,好好学习一下!