java 类与类,类与接口 ,接口与接口关系

package text4;

interface Father{ 
    public abstract void show();
}
interface Mother{
    public abstract void show1();
}
class Son extends Object implements Father,Mother{
    public  void show(){
        System.out.println("nihao");
    }
    public void show1(){
        System.out.println("nihaoa");
    }
}

public class InterfaceDemo3 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Father  f=new Son();
f.show();
Mother m=new Son();
m.show1();
    }

}
View Code

抽象类与接口的关系:

1.成员区别

抽象类:

成员变量 可以变量也可以常量 

构造方法 有

成员方法可以抽象可以飞抽象

接口:

成员变量:只能常量

成员方法:只能抽象

2.关系区别

3.设计理念的不同

抽象类:被继承是 is _a 关系,继承体现的共性功能

接口:被实现体现的是 like_a关系,继承体系的扩展功能  (usb接口)

猜你喜欢

转载自www.cnblogs.com/helloworld2019/p/10623963.html
今日推荐