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

Java Labprogram 7

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

Java Labprogram 7

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

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

You might also like