Untitled
unknown
plain_text
2 years ago
590 B
2
Indexable
class Room {
private int length;
private int width;
public Room(int length, int width) {
this.length = length;
this.width = width;
}
public int getArea() {
return length * width;
}
}
class ReuseClass {
public static void main(String[] args) {
Room room1 = new Room(10, 20);
Room room2 = new Room(15, 25);
int area1 = room1.getArea();
int area2 = room2.getArea();
System.out.println("Area of room1 is: " + area1);
System.out.println("Area of room2 is: " + area2);
}
}Editor is loading...