1 public class juxing { 2 3 4 double length; 5 double wide; 6 7 public juxing(double length1,double wide1){ 8 9 this.length = length1; 10 this.wide = wide1; 11 } 12 public double getarea(){ 13 14 double s = length*wide; 15 return s; 16 17 } 18 19 20 }
1 public class Test { 2 3 public static void main(String[] args) { 4 5 6 7 Juxing j = new Juxing(3, 4); 8 9 System.out.println("矩形的面积是:" + j.getarea()); 10 11 } 12 }