为了账号安全,请及时绑定邮箱和手机立即绑定

我的练习题

 

package com.imooc;

public abstract class Shape {
 double a;
 double b;
 double r;
 public abstract void l();
 public abstract void s();

}


package com.imooc;

public class Rectangle extends Shape {

 @Override
 public void l() {
  // TODO Auto-generated method stub
  Object l1 = 2*(a+b);
  System.out.println(l1);
 }

 @Override
 public void s() {
  // TODO Auto-generated method stub
  double s = a*b;
  System.out.println(s);
 }

}


package com.imooc;

public class Circle extends Shape {

 final double PI = 3.14;

 @Override
 public void l() {
   // TODO Auto-generated method stub
  Object l = 2*PI *r;
  System.out.println(l);
 }

 @Override
 public void s() {
  // TODO Auto-generated method stub
  double s = PI*r*r;
  System.out.println(s);
 }

}


package com.imooc;

public class Test {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Shape shape = new Rectangle();
  shape.a=6.0;
  shape.b=4.0;
  shape.l();
  shape.s();
  
  Shape shape2 = new Circle();
  shape2.r = 4.0;
  shape2.l();
  shape2.s();
  

 }

}

 

正在回答

1 回答

Rectangle just have a and b, and donot have r.

Circle just have r, and donot have a and b.

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java入门第二季 升级版
  • 参与学习       530628    人
  • 解答问题       6091    个

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

进入课程

我的练习题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信