Abstract classes and implement the abstract methods defined

day_15 Package; 
/ ** 
 * abstract class defines a plane pattern 
 * / 
public abstract class PlaneFigure { 
    public abstract the getArea Double (); // get the area defined abstract methods 
    public abstract double getPerimeter (); // get the definition of the abstract perimeter method 
} 
Package day_15; 
// define a rectangle class 
public class PlaneFigure the extends the rectangle { 
    Private Double Wide; 
    Private Double length; 

    public the rectangle () { 

    } 
    public the rectangle (Double Wide, Double length) { 
        this.wide = Wide; 
        this.length length =; 
    } 

    public Double the getArea () {// get the abstract methods override area 
        return wide * length; 
    }
    public double getPerimeter(){  //重写得到周长的抽象方法
        return 2*(wide+length);
    }
}
package day_15;
//定义一个圆类
public class Circle extends PlaneFigure{
    private double r;
    private static final double PI=3.14;

    public Circle(){

    }
    public Circle(double r) {
        this.r = r;
    }

    @Override
    public double getArea() {  //
        return PI*r*r;
    }

    @Override
    public double getPerimeter() {
        return 2*PI*r;
    }
}
package day_15;

public class Test {
    static void main public (String [] args) { 
        Circle Circle Circle new new = (. 3); 
        Print (Circle); 
        the Rectangle Rectangle = new new the Rectangle (3,4-); 
        Print (Rectangle); 
    } 
    public static void Print (PlaneFigure planeFigure) {// static method defined 
        System.out.println ( "current graphics plane information:"); 
        System.out.println ( "\ T area:" + planeFigure.getArea ()); 
        System.out.println ( "\ t perimeter: "+ planeFigure.getPerimeter ()); 
    } 
}

  

Guess you like

Origin www.cnblogs.com/-slz-2/p/11281749.html
Recommended