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);
}
}
两个问题都是选择第一个 添加就好了
Java入门第二季 升级版
530649 学习 · 6091 问题
相似问题