慕运维8340830
2019-10-08 14:43
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);
}
}
zhouchang 和 mianji都是方法吧,调用也应该是c.zhouchang();
而且System.out.println()里输出的方法必须要有返回值,不能是void
我把π变成常亮3了
人后编译器最后两句会报错
Java入门第二季 升级版
530650 学习 · 6091 问题
相似问题