Program 07 : Resizable interface
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.
// Resizable interface
interface Resizable {
void resizeWidth(int width);
void resizeHeight(int height);
// Rectangle class implementing Resizable interface
class Rectangle implements Resizable {
private int width;
private int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
// Implementation of Resizable interface
@Override
public void resizeWidth(int width) {
this.width = width;
System.out.println("Resized width to: " + width);
@Override
public void resizeHeight(int height) {
this.height = height;
System.out.println("Resized height to: " + height);
// Additional methods for Rectangle class
public int getWidth() {
return width;
public int getHeight() {
return height;
public void displayInfo() {
System.out.println("Rectangle: Width = " + width + ", Height = " + height);
// Main class to test the implementation
public class ResizeDemo {
public static void main(String[] args) {
// Creating a Rectangle object
Rectangle rectangle = new Rectangle(10, 5);
// Displaying the original information
System.out.println("Original Rectangle Info:");
rectangle.displayInfo();
// Resizing the rectangle
rectangle.resizeWidth(15);
rectangle.resizeHeight(8);
// Displaying the updated information
System.out.println("\nUpdated Rectangle Info:");
rectangle.displayInfo();
In this program, the Resizable interface declares the methods resizeWidth and resizeHeight.
The Rectangle class implements this interface and provides the specific implementation for resizing the
width and height. The main method in the ResizeDemo class creates a Rectangle object, displays its
original information, resizes it, and then displays the updated information.
Output
$ java ResizeDemo
Original Rectangle Info:
Rectangle: Width = 10, Height = 5
Resized width to: 15
Resized height to: 8
Updated Rectangle Info:
Rectangle: Width = 15, Height = 8