This Java program illustrates the use of interfaces and how a class can implement multiple interfaces to provide different sets of behaviors. In this program, there are two interfaces, Drawable and Resizable, and a class called Shape that implements both of these interfaces. The Shape class provides concrete implementations for the methods defined in these interfaces. Here's an explanation of the program:
In this program, the Shape class implements two interfaces, Drawable and Resizable, which provide different sets of behaviors. When the draw and resize methods are called on an instance of the Shape class, the methods from the implemented interfaces are executed. This allows the Shape class to have the ability to draw and resize, making it a versatile object with multiple behaviors defined by interfaces.
public class Main { public static void main(String[] args) { Shape shape = new Shape(); shape.draw(); shape.resize(); } } interface Drawable { void draw(); } interface Resizable { void resize(); } class Shape implements Drawable, Resizable { @Override public void draw() { System.out.println("Drawing the Shape"); } @Override public void resize() { System.out.println("Resizing the Shape"); } }
Drawing the Shape Resizing the Shape
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions