package com.imooc;
public abstract class Shape{
public abstract double perimeter();
public abstract double area();
}
_______________________________________________________________
package com.imooc;
public class Circle extends Shape{
double r = 3.4;
@Override
public double perimeter(){
retrun Math.PI * 2 * r
}
@Override
public double area(){
return Math.PI * r * r;
}
}
_______________________________________________________________
package com.imooc;
public class initial{
public static void main(String[] args){
Shape cc = new Circle();
Shape rt = new Rectangle();
System.out.println("圆的面积为:"+cc.area());
System.out.println("圆的周长为:"+cc.perimeter());
}
}