這是我自己寫的作業,代碼比較簡單,希望大家看到可以看下并指出可以精簡的部分http://www.xianlaiwan.cn/article/44300
public class Initail {
public static void main(String[] args){
Shape shape = new Circle();
shape.mj();
shape.zc();
Shape shape1 = new Rectangle();
shape1.mj();
shape1.zc();
}
}
public static void main(String[] args){
Shape shape = new Circle();
shape.mj();
shape.zc();
Shape shape1 = new Rectangle();
shape1.mj();
shape1.zc();
}
}
2018-07-02
public abstract class Shape {
public abstract void mj();
public abstract void zc();
}
public abstract void mj();
public abstract void zc();
}
2018-07-02
public class Rectangle extends Shape {
int r = 5;
@Override
public void mj() {
System.out.println(" 圓的面積:"+(Math.PI*r*r));
}
@Override
public void zc() {
System.out.println(" 圓的周長:"+(Math.PI*2*r));
}
}
int r = 5;
@Override
public void mj() {
System.out.println(" 圓的面積:"+(Math.PI*r*r));
}
@Override
public void zc() {
System.out.println(" 圓的周長:"+(Math.PI*2*r));
}
}
2018-07-02