1. package calc;
    2. public class Test {
    3. public static void main(String[] args) {
    4. // TODO Auto-generated method stub
    5. Square sq1,sq2;
    6. sq1 = new Square();
    7. sq2 = new Square(3.2);
    8. sq1.area();
    9. System.out.println("Sq2的周长是 "+ sq2.perimeter());
    10. }
    11. }
    1. package calc;
    2. public class Square {
    3. double length;
    4. Square(){
    5. this.length = 2.0;
    6. }
    7. Square(double length){
    8. this.length = length;
    9. }
    10. public void area(){
    11. System.out.println("the area is "+ length * length);
    12. }
    13. public double perimeter(){
    14. return length * 6;
    15. }
    16. }