Develop a JAVA program to create an interface Resizable with methods resizeWidth(int width)
and resizeHeight(int height) that allow an object to be resized. Create a class Rectangle that
implements the Resizable interface and implements the resize methods.
Save Filename as: rect_resize.java
Solution:-
interface Resizable
void resizeWidth (int width);
void resizeHeight (int height);
class Rectangle implements Resizable
private int width;
private int height;
// Constructor
public Rectangle (int width, int height)
[Link] = width;
[Link] = height;
public void resizeWidth (int width)
[Link] = width;
}
public void resizeHeight (int height)
[Link] = height;
// Additional method to get the dimensions
public void getDimensions ()
[Link] ("Width: " + width + ", Height: " + height);
public class rect_resize
public static void main (String[] args)
Rectangle r = new Rectangle (5, 7);
[Link] ("Original Dimensions:");
[Link] ();
[Link] (8);
[Link] (10);
[Link] ("\nResized Dimensions:");
[Link] ();
}
Compile As: javac rect_resize.java
Run As: java rect_resize
Output:
Original Dimensions:
Width: 5, Height: 7
Resized Dimensions:
Width: 8, Height: 10