package Test; public class test5 { int count; public static void main(String[] args) { // TODO Auto-generated method stub //建立矩形的类的对象 Rectangle rect = new Rectangle(2,3); rect.getArea(); rect.getPeri(); } } class Rectangle{ //矩形的宽 private double width = 0.0; //矩形的高 private double height = 0.0; //矩形的面积 private double area = 0.0; //矩形的周长 private double peri = 0.0; Rectangle(double width,double height){ this.width = width; this.height = height; } //计算矩形的面积 public void getArea() { area = width*height; System.out.println("矩形的面积是:"+area); } //计算矩形的周长 public void getPeri() { peri = (height+width)*2; System.out.println("矩形的周长是:"+peri); } }