class constructorDemo {
public static void main(String[]args ){
Rectangle r=new Rectangle(3,4);
System.out.println(r.getPerimeter());
System.out.println(r.getArea());
}
}
class Rectangle {
private int wide;
private int length;
public Rectangle(int wide ,int length){
this.wide=wide;
this.length=length;
}
public void setWide(int wide){
this.wide=wide;
}
public void setLength(int length){
this.length=length;
}
public int getWide(){
return wide;
}
public int getLength(){
return length;
}
public int getPerimeter(){
return (wide+length)<<1;
}
public int getArea(){
return wide*length;
}
} |
|