---接口代码:
package com.yikuan.cn;
public interface Shape { public abstract void area();}
--两个子类代码:
public class Circle implements Shape {
private double r; public Circle(double r) { super(); this.r = r; } @Override public void area() { System.out.println(2*Math.PI*r); }}
public class Area implements Shape{
private double r; public Area(double r) { super(); this.r = r; } @Override public void area() { System.out.println(Math.PI*r*r); }}
---测试类代码:
package com.yikuan.cn;
public class Test1 { public static void main(String[] args) { Area a1 = new Area(5); a1.area(); Circle c1 = new Circle(3); c1.area(); }}