我的練習(xí)題
?
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();
??
?}
}
?
2015-12-18
Rectangle just have a and b, and donot have r.
Circle just have r, and donot have a and b.