EXPERIMENT-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
// Interface Resizable
interface Resizable {
void resizeWidth(int width);
void resizeHeight(int height);
}
// Rectangle class implementing Resizable
class Rectangle implements Resizable {
private int width;
private int height;
// Constructor
public Rectangle(int width, int height) {
[Link] = width;
[Link] = height;
}
PREPARED BY- MS. ITISHREE BARIK. ASST. PROFESSOR, DEPT OF CSE, SIR MVIT
// Implement resizeWidth method
@Override
public void resizeWidth(int width) {
[Link] = width;
[Link]("Width resized to: " + [Link]);
}
// Implement resizeHeight method
@Override
public void resizeHeight(int height) {
[Link] = height;
[Link]("Height resized to: " + [Link]);
}
// Method to display rectangle dimensions
public void display() {
[Link]("Current Rectangle Dimensions → Width: " +
width + ", Height: " + height);
}
}
// Main class
public class TestResizable {
public static void main(String[] args) {
PREPARED BY- MS. ITISHREE BARIK. ASST. PROFESSOR, DEPT OF CSE, SIR MVIT
Rectangle rect = new Rectangle(10, 20);
[Link](); // show original size
[Link](30); // resize width
[Link](40); // resize height
[Link](); // show updated size
}
}
OUTPUT
Current Rectangle Dimensions → Width: 10, Height: 20
Width resized to: 30
Height resized to: 40
Current Rectangle Dimensions → Width: 30, Height: 40
PREPARED BY- MS. ITISHREE BARIK. ASST. PROFESSOR, DEPT OF CSE, SIR MVIT
EXPERIMENT-8
Develop a JAVA program to create an outer class with a function
display. Create another class inside the outer class named inner
with a function called display and call the two functions in the
main clas
// Outer class
class Outer {
void display() {
[Link]("Display method of Outer class");
}
// Inner class
class Inner {
void display() {
[Link]("Display method of Inner class");
}
}
}
PREPARED BY- MS. ITISHREE BARIK. ASST. PROFESSOR, DEPT OF CSE, SIR MVIT
// Main class
public class TestInnerClass {
public static void main(String[] args) {
// Create object of Outer class
Outer outerObj = new Outer();
[Link](); // Call outer class display
// Create object of Inner class using Outer object
[Link] innerObj = [Link] Inner();
[Link](); // Call inner class display
}
}
OUTPUT
Display method of Outer class
Display method of Inner class
PREPARED BY- MS. ITISHREE BARIK. ASST. PROFESSOR, DEPT OF CSE, SIR MVIT