java中接口的实现

2017-03-01  本文已影响0人  刘恒廷
package demo1;
/**接口的命名
  interface  interfaceName{
   全局变量;
   抽象方法;
}
*/
interface Inter{
    public static final int AGE = 100;//全局变量
    public abstract void tell();//抽象方法
}

interface Inter1{
    public abstract void speak();
}
//接口的实现  使用implements   一个类可以实现多个接口
class A implements Inter,Inter1{
    @Override
    //需要重写接口的抽象方法才能使用
    public void tell(){
        System.out.println(Inter.AGE);
    }

    @Override
    public void speak() {
        // TODO Auto-generated method stub
        
    }
}

public class interDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        A a = new A();
        a.tell();
        //全局常量可以直接使用接口名来调用
        System.out.println(Inter.AGE);
    }

}
上一篇 下一篇

猜你喜欢

热点阅读