public abstract class Telphone { // 抽象类
public abstract void zhouchang(); //抽象方法
public abstract void mianji();
}
public class Circle extends Telphone {
int a;
final float Pi=3.14f;
public Circle(int a){ //构造方法 来产生对象的属性
this.a=a; //两个a一样 为了防止看不懂 就加this
}
@Override
public void zhouchang() {
int z=4*a;
System.out.println("周长"+z);
}
@Override
public void mianji(double a) {
Stringm=String.format("%.2f",Pi*a*a); // 格式化输出
System.out.println("面积"+m);
}
}
public class Rectangle extends Telphone {
int a;
int b;
public Rectangle(int a,int b){
this.a=a;
this.b=b;
}
@Override
public void zhouchang() {
int z=2*(a+b);
System.out.println("周长"+z);
}
@Override
public void mianji() {
int m=a*b;
System.out.println("面积"+m);
}
}
public class Initiaal {
public static void main(String[] args) {
Telphone t1=new Circle(2);
t1.mianji();
t1.zhouchang();
Telphone t2=new Rectangle(3,4);
t2.zhouchang();
t2.mianji();
}
}
面积12.56
周长8
周长14
面积12