3.第二单元任务五实训:通过程序设计几何图形接口(Shape),实现类矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显 |
您所在的位置:网站首页 › 5个正方形组成的图形有几种类型 › 3.第二单元任务五实训:通过程序设计几何图形接口(Shape),实现类矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显 |
3.第二单元任务五实训:通过程序设计几何图形接口(Shape),实现类矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显示。 public class ShapeTest { publicstatic void print(Shape shape){ System.out.println(shape.getClass()+":"+"面积:"+shape.area()); System.out.println(shape.getClass()+":"+"周长:"+shape.perimeter()); } publicstatic void main(String[] args) { Shapeshape=new Rectangle(4,5); print(shape); shape=newCircle(4); print(shape); shape=newSquare(5); print(shape); } } public interface Shape { public double area(); |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |