代码:
package txt1;
public class sy7 {
public static void main(String[] args) {
cli c=new cli();
c.setH(4.2);
c.setR(2.8);
//c.mj(c.getH(),c.getR());
c.cli();
c.show();
cli c1=new cli(1.2,3.5);
c1.cli();
c1.show();
}
}
class cli{
private double r,h;
public cli(){
}
public cli(double a,double b){
this.h=a;
this.r=b;
}
public void setR(double r){
this.r=r;
}
public double getR(){
return this.r;
}
public double getH() {
return h;
}
public void setH(double h) {
this.h = h;
}
// public void mj(double a,double b){
// System.out.println("面积是 : "+2*a*b);
// }
public void show(){
System.out.println("长方形的长是: "+this.r+" 宽是: "+this.h);
}
public void cli(){
System.out.println("面积是 : "+2*this.h*this.r);
}
}