0% found this document useful (0 votes)
9 views

Program 07 Resizable interface

The document describes a JAVA program that implements a Resizable interface with methods for resizing width and height. A Rectangle class is created that implements this interface, allowing it to adjust its dimensions. The main method demonstrates creating a Rectangle object, resizing it, and displaying the updated dimensions.

Uploaded by

fevawov660
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Program 07 Resizable interface

The document describes a JAVA program that implements a Resizable interface with methods for resizing width and height. A Rectangle class is created that implements this interface, allowing it to adjust its dimensions. The main method demonstrates creating a Rectangle object, resizing it, and displaying the updated dimensions.

Uploaded by

fevawov660
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like