1.接口繼承
接口繼承需要用 implements
類繼承用extend
2.接口示例
interface(父類)
package interfaceTest;
public interface Animal {
int ID = 1;// 定義全局變量
void breathe();
void run();
}
implements(子類繼承)
package interfaceTest;
class Dog implements Animal {
public void breathe() {
System.out.println("狗在呼吸");
}
public void run(){
System.out.println("狗在跑");
}
public void doa(){
System.out.println("我是子");
}
}
package interfaceTest;
public class PrintDog {
public static void main(String[] args) {
// TODO Auto-generated method stub
Dog dog=new Dog();
dog.breathe();
dog.run();
dog.doa();
System.out.println(dog.ID);
}
}