Interface Example
This program demonstrates interface usage.
Problem Statement
Write a Java program to define interface Drawable with method draw().
Source Code
| 1 | interface Drawable { |
| 2 | void draw(); |
| 3 | } |
| 4 | class Circle implements Drawable { |
| 5 | public void draw(){ System.out.println("Drawing Circle"); } |
| 6 | } |
| 7 | public class InterfaceExample { |
| 8 | public static void main(String[] args) { |
| 9 | System.out.println("Eduinq Interface Example"); |
| 10 | Drawable d=new Circle(); |
| 11 | d.draw(); |
| 12 | } |
| 13 | } |
Program Output
Eduinq Interface Example Drawing Circle
Explanation
Interface defines contract without implementation. - Circle class implements interface and provides method body. - Interfaces allow multiple classes to share common behavior signatures. Conclusion: Shows how to use interfaces in Java.