/**
- @Description 接口(Interface)demo:
- @Author xiang
- @Date 2020/9/18 17:04
/
//定义四边形父类
public class QuadrangleUseInterface {
public static void main(String[] args) {
drawTest[]d= {new ParallelogramgleUser(), new SquareUseInterface()};
for (int i=0;i<d.length;i++){
d[i].draw();
}
}
}
/定义接口和方法,注意接口不可以写方法体*/
interface drawTest{ void draw();}
/定义平行四边形类,该类继承四边形类,并实现drawTest接口/
class ParallelogramgleUser extends QuadrangleUseInterface implements drawTest{
/实现接口必须重写接口里面方法体/
public void draw() { System.out.println("平行四边形"); }
}
/定义正方形类,该类继承四边形类,并实现drawTest接口/
class SquareUseInterface extends QuadrangleUseInterface implements drawTest{
public void draw() { System.out.println("正方形"); }
}