继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

奇妙记忆
关注TA
已关注
手记 1
粉丝 0
获赞 0

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();
}

}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP