public interface Paintable {
public void draw();
}
public class Quadrangle {
public void doAnything()
{
System.out.println("四边形提供的方法");
}
}
public class Parallelogram extends Quadrangle implements Paintable{
@Override
public void draw() {
System.out.println("绘制平行四边形!");
}
}
public class Square extends Quadrangle implements Paintable{
@Override
public void draw()
{
System.out.println("绘制正方形!");
}
}
public class Circle implements Paintable{
@Override
public void draw()
{
System.out.println("绘制圆形!");
}
}
public class Main {
public static void main(String[] args) {
Square s=new Square();
s.doAnything();
s.draw();
Parallelogram p=new Parallelogram();
p.draw();
p.doAnything();
Circle c=new Circle();
c.draw();
}
}
运行结果:
四边形提供的方法
绘制正方形!
绘制平行四边形!
四边形提供的方法
绘制圆形!