问答详情
源自:10-3 Java 中的抽象类

来个大佬帮一下吧。。

package com.chouxiang;


public abstract class Shape {

int r;

int a;

int b;

public abstract void zhouchang();

public abstract void mianji();

}

package com.chouxiang;


public class juxing extends Shape {


@Override

public void zhouchang() {

System.out.println((a+b)*2);


}


@Override

public void mianji() {

System.out.println(a*b);

}


}

package com.chouxiang;


public class yuanxing extends Shape {


@Override

public void zhouchang() {

// TODO Auto-generated method stub

System.out.println(6*r);

}


@Override

public void mianji() {

// TODO Auto-generated method stub

System.out.println(3*r*r);

}


}

package com.chouxiang;


public class test {


public static void main(String[] args) {

// TODO Auto-generated method stub

Shape c=new juxing();

Shape d=new yuanxing();

c.a=6;

c.b=4;

d.r=2;

System.out.println("矩形周长为"+c.zhouchang+"\n"+"矩形面积为"+c.mianji);

System.out.println("圆形周长为"+d.zhouchang+"\n"+"圆形面积为"+d.mianji);

}


}


提问者:慕运维8340830 2019-10-08 14:43

个回答

  • 迷茫的小学生gpf
    2019-10-29 11:57:45

    zhouchang 和 mianji都是方法吧,调用也应该是c.zhouchang();

    而且System.out.println()里输出的方法必须要有返回值,不能是void

  • 慕运维8340830
    2019-10-08 14:44:53

    我把π变成常亮3了

    人后编译器最后两句会报错