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();
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦