package calc;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Square sq1,sq2;
sq1 = new Square();
sq2 = new Square(3.2);
sq1.area();
System.out.println("Sq2的周长是 "+ sq2.perimeter());
}
}
package calc;
public class Square {
double length;
Square(){
this.length = 2.0;
}
Square(double length){
this.length = length;
}
public void area(){
System.out.println("the area is "+ length * length);
}
public double perimeter(){
return length * 6;
}
}