手记

抽象类 根据课程自己编写的

package com.zzxy;

public abstract class Shap {
public abstract void perimeter();
public abstract void area();
}
package com.zzxy;

public class Rectangle extends Shap {
public int width;
public int heigh;

public Rectangle(int width, int heigh) {
    super();
    this.width = width;
    this.heigh = heigh;
}

@Override
public void perimeter() {
    // TODO Auto-generated method stub
    System.out.println(2*(width+heigh));
}

@Override
public void area() {
    // TODO Auto-generated method stub
    System.out.println(width*heigh);
}

}

}
package com.zzxy;

public class Circle extends Shap {

public int r;
public double pi;
public Circle(int r, double pi) {
super();
this.r = r;
this.pi = pi;
}

@Override
public void perimeter() {
// TODO Auto-generated method stub
System.out.println(2rpi);
}
@Override
public void area() {
// TODO Auto-generated method stub
System.out.println(rrpi);
}

}
package com.zzxy;

public class Test {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Shap obj1=new Rectangle(2,3.14);
    Shap obj2=new Circle(2,4);
    obj1.area();
    obj1.perimeter();
    obj2.area();
    obj2.perimeter();
}

}

0人推荐
随时随地看视频
慕课网APP