Interface Inheritance Example

This program demonstrates inheritance among interfaces.

Problem Statement

Write a Java program where AdvancedPlayable extends Playable interface.

Source Code

1 interface Playable { void play(); }
2 interface AdvancedPlayable extends Playable { void stop(); }
3 class MusicSystem implements AdvancedPlayable {
4 public void play(){ System.out.println("Eduinq Music Playing"); }
5 public void stop(){ System.out.println("Eduinq Music Stopped"); }
6 }
7 public class InterfaceInheritance {
8 public static void main(String[] args) {
9 System.out.println("Eduinq Interface Inheritance");
10 AdvancedPlayable ap=new MusicSystem();
11 ap.play(); ap.stop();
12 }
13 }

Program Output

					Eduinq Interface Inheritance
Eduinq Music Playing
Eduinq Music Stopped
				

Explanation

Interfaces can extend other interfaces, creating hierarchical contracts. - AdvancedPlayable inherits play() from Playable and adds stop(). - MusicSystem implements both methods, showing how interface inheritance enforces extended behavior. - This design is powerful in large systems where contracts evolve over time, ensuring backward compatibility while adding new features. Conclusion: Shows interface inheritance example.

Quick Links to Explore