-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.java
40 lines (34 loc) · 969 Bytes
/
interface.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
interface Resizable {
void resizeWidth(int width);
void resizeHeight(int height);
}
class Rectangle implements Resizable {
private int width;
private int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public void resizeWidth(int width) {
this.width = width;
}
@Override
public void resizeHeight(int height) {
this.height = height;
}
@Override
public String toString() {
return "Rectangle (width: " + width + ", height: " + height + ")";
}
}
public class ResizableDemo {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(10, 20);
System.out.println("Original Rectangle: " + rectangle);
// Resize the rectangle
rectangle.resizeWidth(15);
rectangle.resizeHeight(25);
System.out.println("Resized Rectangle: " + rectangle);
}
}