package polymorphic1;
public abstract class MyShape {
public abstract void getArea();
public abstract void getPerimeter();
}
public class Cicle extends MyShape {
//String name;
double r;
public static final double PI=3.14;
public Cicle( double r) {
this.r =r;
}
public void getArea() {
System.out.println("圆的面积是"+PI*r*r);
}
public void getPerimeter() {
System.out.println("圆的周长是"+PI*r*2);
}
}
public class Rectangle extends MyShape{
int a,b;
public Rectangle(int a,int b) {
this.a=a;
this.b=b;
}
public void getArea() {
System.out.println("矩形的面积是"+(a*b));
}
public void getPerimeter() {
System.out.println("矩形的周长是"+(a+b));
}
}
public class Demo7 {
public static void main(String []args) {
MyShape m=new Cicle(4);
MyShape n=new Rectangle(4,6);
m.getArea();
m.getPerimeter();
n.getArea();
n.getPerimeter();
}
}