矩形类返回值问题
package com;public class Rectangle1 {
private double width;
private double length;
public Rectangle(){
this.width=5;
this.length=6;
}
public Rectangle(double w,double l){
this.width=w;
this.length=l;
}
public double area(){ //求面积
return this.width*this.length;
}
public double perimeter(){ //求周长
return 2*(this.width+this.length);
}
public static void main(String[] args) {
Rectangle r1=new Rectangle();
System.out.println("r1的周长:"+r1.perimeter());
System.out.println("r1的面积:"+r1.area());
System.out.println();
Rectangle r2=new Rectangle(10,20);
System.out.println("r2的周长:"+r2.perimeter());
System.out.println("r2的面积:"+r2.area());
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
}红色的这几行为什么要有?搞不懂