人狠话不多,直接上代码
abstract class solver{//模糊类 public abstract void getArea(); // 获取面积 public abstract void getPan(); // 获取周长 } class rectangle extends solver{//长方形 private double a; private double b; public void getPan() { double c=a+b+b+a; System.out.println("周长为"+c); } public void getArea(){ System.out.println("面积为"+a*b); } public rectangle(double a,double b){ this.a=a; this.b=b; } public static void main(String[] args) { rectangle a1= new rectangle(1,2); a1.getArea(); a1.getPan(); } } class circle extends solver{//圆 private double r; double a=Math.PI; public void getPan() { System.out.println("周长为"+a*r*2); } public void getArea(){ System.out.println("面积为"+a*r*r); } public circle(double r){ this.r=r; } public static void main(String[] args) { circle a1= new circle(1); a1.getArea(); a1.getPan(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)