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)
this.width = width;
this.height = height;
public void resizeWidth (int width)
this.width = width;
}
public void resizeHeight (int height)
this.height = height;
// Additional method to get the dimensions
public void getDimensions ()
System.out.println ("Width: " + width + ", Height: " + height);
public class rect_resize
public static void main (String[] args)
Rectangle r = new Rectangle (5, 7);
System.out.println ("Original Dimensions:");
r.getDimensions ();
r.resizeWidth (8);
r.resizeHeight (10);
System.out.println ("\nResized Dimensions:");
rectangle.getDimensions ();
}
Compile As: javac rect_resize.java
Run As: java rect_resize
Output:
Original Dimensions:
Width: 5, Height: 7
Resized Dimensions:
Width: 8, Height: 10