首页 > 代码库 > 面积比较的多态
面积比较的多态
package Mian; public class Geobject { double findArea(){ return 0; } double equalArea(Geobject s){ return this.findArea()-s.findArea(); } }
package Mian; public class Circle extends Geobject{ double radius; public Circle(double radious) { super(); this.radius = radius; } public double getRadious() { return radius; } public void setRadious(double radious) { this.radius = radius; } double findArea(){ return 3.14*this.radius*this.radius; } }
package Mian; public class Rec extends Geobject{ double width; double height; public Rec(double width, double height) { super(); this.width = width; this.height = height; } double findArea(){ return this.height*this.width; } }
package Mian; public class Test { public boolean equalArea(Geobject s, Geobject s1){ return s.findArea()==s1.findArea(); } public static void main(String[] args) { Circle c=new Circle(5); Rec r=new Rec(4, 5); Test t=new Test(); if(t.equalArea(c, r)){ System.out.println("面积相等"+c.findArea()); }else{ System.out.println("面积不相等"); } System.out.println(c.equalArea(r)); }}
面积比较的多态
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。