PROGRAM 7:
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
Here are clear step-by-step instructions to perform this experiment in
Eclipse IDE, along with the corrected error-free code.
How to Perform This Experiment in Eclipse IDE
Follow these steps exactly:
Open Eclipse IDE
• Open Eclipse.
• Click File → New → Java Project.
• Enter project name: ResizableDemo
• Click Finish.
Create a Package
• Right-click on src → New → Package
• Enter name:
• employee
• Click Finish.
Create Interface File: [Link]
• Right-click on the package employee
• Select New → Interface
• Name it:
• Resizable
• Paste this code:
package employee;
interface Resizable {
void resizeWidth(int width);
void resizeHeight(int height);
}
Create Class File: [Link]
• Right-click on package employee → New → Class
• Name it:
• Rectangle
• Paste this code (error-free):
package employee;
class Rectangle implements Resizable {
private int width;
private int height;
public Rectangle(int width, int height) {
[Link] = width;
[Link] = height;
public void resizeWidth(int width) {
[Link] = width;
public void resizeHeight(int height) {
[Link] = height;
}
public void printSize() {
[Link]("Width: " + width + ", Height: " + height);
}
}
Create Main Class: [Link]
• Right-click on package employee → New → Class
• Name it:
• Point
• Check public static void main(String[] args)
• Paste this corrected code:
package employee;
public class Point {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(100, 150);
[Link]();
[Link](150);
[Link](200);
[Link]();
Run the Program
• Right-click on [Link]
• Click Run As → Java Application
Expected Output (as given)
Width: 100, Height: 150
Width: 150, Height: 200
RESULT
The Java program demonstrating the use of interfaces was successfully created and executed
in Eclipse IDE, and the output was verified.