用java面向对象(方学到类和对象,传参此雕刻壹

时间:2018-10-03      作者:admin

  class Circle {

  private double radius;

  static double PI = 3.14;

  public Circle(double radius) {

  super();

  this.radius = radius;

  }

  public double getRadius() {

  return radius;

  }

  public void setRadius(double radius) {

  this.radius = radius;

  }

  }

  public class X4_3_1 {

  public static void main(String[] args) {

  Circle c1 = new Circle(100);

  Circle c2 = new Circle(200);

  System.out.println("c1的周长:" + 2 * c1.PI * c1.getRadius());

  System.out.println("c1的面积:" + c1.PI * c1.getRadius() * c1.getRadius());

  System.out.println("c2的周长:" + 2 * c2.PI * c2.getRadius());

  System.out.println("c2的面积:" + c2.PI * c2.getRadius() * c2.getRadius());

  }

  }

标签: