java是什么 用Java定义一个形状类Shape?
浏览量:1054
时间:2021-03-14 12:27:45
作者:admin
用Java定义一个形状类Shape?
publicabstractclassShape{publicabstractvoidarea()}classCircleextendsShape{privateDoubleRadiusPrivatedDoubleScircle(双半径){this.radius=半径}publicvoidarea(){S=3.14*半径*radiusSystem.out.println(S) }}ClassRectExtendShape{privateDoubleLengthPrivateDoubleWidthPrivateDoubleStrect(doublelength,doublewidth){this.length=长度this.宽度=宽度}publicvoidarea(){S=长度*宽度系统.out.println(S) }}类测试{publicstaticvoidmain(String[]args){Circlea=newCircle(3)a.area()Rectb=newRect(3,4)b.area()}
版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。