2020-4-19
package hm_4_19; public class Rectangle { public int length ; public int width; public Rectangle(int length, int width) { super(); this.length = length; this.width = width; } public int getArea() { // 面积 int area = length*width; return area; } public int getPer() { // 周长 int per = (length+width)*2; return per; } public void showAll() { // 所有属性 System.out.println("长"+length+"宽"+width+"面积"+getArea()+"周长"+getPer()); } public static void main(String[] args) { Rectangle r = new Rectangle(20, 30); r.showAll(); } }