0% found this document useful (0 votes)
6 views5 pages

Java Resizable Interface and Inner Class

The document contains two Java programming experiments. Experiment 7 involves creating a Resizable interface and a Rectangle class that implements this interface, allowing for resizing of its dimensions. Experiment 8 demonstrates the creation of an outer class with a display method and an inner class that also has a display method, showcasing how to call both methods in the main class.

Uploaded by

sanketh.s577425
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)
6 views5 pages

Java Resizable Interface and Inner Class

The document contains two Java programming experiments. Experiment 7 involves creating a Resizable interface and a Rectangle class that implements this interface, allowing for resizing of its dimensions. Experiment 8 demonstrates the creation of an outer class with a display method and an inner class that also has a display method, showcasing how to call both methods in the main class.

Uploaded by

sanketh.s577425
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

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

You might also like