
class Rectangle{
double width;
double height;
public Rectangle(double width,double height){
this.width=width;
this.height=height;
}
double getArea() {
return width*height; }
double getPerimeter() {
return 2*(width+height);
}
}
没什么好说的,无参方法的调用要用this
本文详细介绍了Java中Rectangle类的构造函数,包括接受宽度和高度作为参数的构造方法,以及计算面积和周长的getArea()和getPerimeter()方法。特别提到无参方法调用时使用this关键字的情况。
1万+

被折叠的 条评论
为什么被折叠?



