实验环境:windows10
创建主类:
package ric;
public class tr {
private int length;
private int width;
public int getLength() {
return (length+length)*2;//设置参数
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width*width;设置参数
}
public void setWidth(int width) {
this.width = width;
}
}
创建测试类:
package ric;
public class test {
public static void main(String[] args) {
tr a=new tr();
a.setLength(2);//设置参数
a.setWidth(5);//设置参数
System.out.println("周长:"+a.getLength()+"面积:"+a.getWidth());//输出参数
}
}
输出答案-样板
周长:8面积:25