java中接口的实现
作者:
刘恒廷 | 来源:发表于
2017-03-01 00:43 被阅读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);
}
}
本文标题:java中接口的实现
本文链接:https://www.haomeiwen.com/subject/ojofgttx.html
网友评论