/**  * Shape接口  * @author chen  *  */ public interface Shape {     public abstract double area(double d);      } /**  * Square类实现Shape接口  * @author chen  *  */ public class Square implements Shape{     @Override     public double area(double width) {         // TODO Auto-generated method stub         return width*width;     }   } /**  * Circle类实现Shape接口  * @author chen  *  */ public class Circle implements Shape{     @Override     public double area(double radius) {         // TODO Auto-generated method stub         return Math.PI*radius*radius;     } } /**  * 测试类  * @author chen  *  */ public class Test {     @org.junit.Test     public void test(){         Square square = new Square();         System.out.println("正方形边长为2的面积是:"+square.area(2));         Circle circle = new Circle();         System.out.println("半径为3的圆的面积是:"+circle.area(3));     } }
点赞 评论

相关推荐

09-28 01:10
中山大学 运营
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务