类的抽象与封装

编写一个圆类。该类拥有(1)成员变量Radius;(2)两个构造方法circle(),circle(double r);(3)三个成员方法double getarea (),double getperimeter(),void show(),

编写应用程序,创建类的对象,分别设置圆的半径,圆柱体的高,计算并分别显示圆半径,圆面积,圆周长,圆柱体的体积。

public class  Circle

{    private double  Radius;

      public  double getRadius(){

     return  Radius;

}

public void setRadius(double  radius){

Radius=radius;

}

 

public Circle(){

System.out.printin("圆!");}

public Circle(double r){

this.radius=r;

}

public double getArea(double r)

{return Math.PI*r*r;

}

public  double getPerimeter(double r){

return  2*Math.PI*r;

}

public void show()

{System.out.println("圆的半径:+getRadius(radius));

System.out.println("圆的面积:+getArea(Radius));

System.out.println("圆的周长:+getPerimeter(Radius));

}

public class Cylinder  extends Circle{

private double hight ;

public Cylinder (double r,double h){

super (r);

this.hight=h;

}

public double getVolume(){

return Math.PI*this.getRadius()*this.getRadius*this.getRadius()*hight;}

public void showVolume(){

System.out.println("圆柱体的体积:+this.getVolume());

}

}

 

posted on 2018-04-23 21:38  重生!!!  阅读(152)  评论(0编辑  收藏  举报