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);
}
}