首页 > 代码库 > 面积比较的多态

面积比较的多态

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));


    }}

 

面积比较的多态