- class Test_Rectangle02 {
- public static void main(String[] args) {
- Rectangle02 rec1=new Rectangle02();
- rec1.setHigh(3);
- rec1.setWidth(4);
- System.out.print("Circle is "+rec1.getCircle()+" "+"Area is "+rec1.getArea());
- System.out.println();
- Rectangle02 rec2=new Rectangle02(5,6);
- rec2.show();
- }
- }
- class Rectangle02{
- private int high;
- private int width;
- public Rectangle02(){}
- public Rectangle02(int high,int width){
- this.high=high;
- this.width=width;
- }
- public void setHigh(int high){
- this.high=high;
- }
- public void setWidth(int width){
- this.width=width;
- }
- public int getCircle(){
- return 2*(high+width);
- }
- public int getArea(){
- return high*width;
- }
- public void show(){
- System.out.print("High is "+high+" "+"width is "+width);
- }
- }
复制代码 |
|