能出结果 但是编译显示错误,各位大神看看

来源:10-5 Java 中的接口

qq_橙子_33

2017-08-18 11:06

package com.imooc;

public abstract class Shape {

public abstract void zhouchang(double a,double b);

public abstract void zhouchang(double r);

public abstract void area(double a,double b);

public abstract void area(double r);

}


package com.imooc;

public class Rectangle extends Shape {

@Override

public void zhouchang(double a, double b) {

// TODO Auto-generated method stub

double s=2*(a+b);

System.out.println("矩形的周长是: "+s);

}


@Override

public void area(double a, double b) {

// TODO Auto-generated method stub

double s=a*b;

System.out.println("矩形的面积是: "+s);

}

}


package com.imooc;

public class Circle extends Shape {

@Override

public void zhouchang(double r) {

// TODO Auto-generated method stub

double s=2*3.14*r;

System.out.println("圆的周长是: "+s);

}

@Override

public void area(double r) {

// TODO Auto-generated method stub

double s=3.13*r*r;

System.out.println("圆的面积是: "+s);

}

}


package com.imooc;

public class Initial {

public static void main(String[] args) {

// TODO Auto-generated method stub

Rectangle rec=new Rectangle();

rec.zhouchang(3, 4);

rec.area(3, 4);

Circle cir=new Circle();

cir.zhouchang(3);

cir.area(3);

}

}


写回答 关注

1回答

  • 看看别人家的孩子
    2017-08-18 11:49:35
    已采纳

    http://img.mukewang.com/5996636a000104e809810397.jpg

    http://img.mukewang.com/5996636b0001e5de10400381.jpg

    两个问题都是选择第一个 添加就好了

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530649 学习 · 6091 问题

查看课程

相似问题