0% found this document useful (0 votes)
125 views4 pages

Lab Programs 7 & 8

Java

Uploaded by

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

Lab Programs 7 & 8

Java

Uploaded by

Madhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Lab 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. AIN: To write a Java program to create a class Rectangle that implements the Resizable interface and implements the resize methods. interface Resizable { void resizeWidth(int width); void resizeHeight(int height); } class Rectangle implements Resizable { private int width; private int height; public Rectangle(int width, int height) s.width = width; this.height = height; - peDRIELald ‘resizemiaen (dine width) this.width = width; + public void resizeHeight (int height) < + public int getWwidth() { + this.height = height; return width; public int getHeight () { return height; } public class ResizableDemo public static void main(String{] args) © pessoa reccarnie «toe nacserielum, ils system, out. pris rectangle.getwidth() + An("Original Rectangle: Width=" + , Height=" + rectangle.getHeight ()); rectangle. resizeWidth(15); rectangle. resizeHeight(30); System. out.println("Resized Rectangle: Width=" + rectangle.getWidth() +", Height=" + rectangle.getHeight()); + , output: Original Rectangle: Width=10, Height=20 Resized Rectangle: Width=15, ‘Heigh RESULT: Thus, the program to create a class Rectangle that implements ‘the Resizable interface and implements the resize methods has been executed successfully and the output was verified. Lab Program 8 Develop a JAVA progran 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 class. AIM: To write 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 class. class OuterClass { void display() { System.out.printIn("This is the display method of the outer class. class InnerClass void display() { System.out.printIn("This is the display method of the dnmer class"); } + public class MainClass { public static void main(String{] args) OuterClass outer = new uterClass(); OuterClass.InnerClass inner = outer.new InnerClass(); outer.display(); // Call the display method of the outer class p meradisplayl)i 1/ Call the display method at the Amer: class + output: This is the display method of the outer class. This is the display method of the inner class. RESULT: Thus, the program to write a Java program to create an outer class with a function display and to Create another class inside the outer class named inner with a function called display and call the two functions in the main class has been executed successfully and the output was verified.

You might also like