package com.imooc;
public abstract class shape {
public abstract void Rectangle();//周长
public abstract void circle();//面积
}
//下面是长方形的子类
package com.imooc;
//这是个长方形的子类
public class rectangle extends shape {
int svm=10;
int sam=5;
@Override
public void Rectangle() {
// TODO Auto-generated method stub
int avg=svm+sam;
System.out.println("这个长方形的周长是:"+avg);
}
@Override
public void circle() {
// TODO Auto-generated method stub
int ave=svm*sam;
System.out.println("这个长方形的面积是:"+ave);
}
}
//下面是圆的子类
package com.imooc;
//这是个圆形的子类
public class Circle extends shape {
int svm=5;
float sam=3.14f;
@Override
public void Rectangle() {
// TODO Auto-generated method stub
double avg=sam*(svm*2);
System.out.println("圆周的长是"+avg);
}
@Override
public void circle() {
// TODO Auto-generated method stub
float ave=sam*(svm*svm);
System.out.println("圆的面积是"+ave);
}
}
//下面是测试
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
shape obj1=new rectangle();
shape obj2=new Circle();
obj1.Rectangle();
obj1.circle();
obj2.Rectangle();
obj2.circle();
}
}