Implement multiple interfaces in Java


This program demonstrates the use of interfaces in Java to create a SmartPhone class that implements the Camera and Player interfaces.

The Phone class defines basic phone functionalities such as voiceCall() and sms() methods. The Camera interface defines methods for taking pictures and recording videos, while the Player interface defines methods for playing, pausing, and stopping music.

The SmartPhone class extends Phone and implements Camera and Player. It overrides the interface methods to provide specific implementations for each of them.

In the main() method, an object of the SmartPhone class is created, and various methods such as voiceCall(), sms(), click(), record(), play(), pause(), and stop() are called to demonstrate the functionality of the SmartPhone class.

Source Code

//How Multiple inheritance can be achieved by implement multiple interfaces
class Phone
{
    void voiceCall()
    {
        System.out.println("Make VoiceClass");
    }
    void sms()
    {
        System.out.println("We Can send SMS");
    }
}
interface Camera
{
    void click();
    void record();
}
 
interface player
{
    void play();
    void pause();
    void stop();
}
 
class SmartPhone extends Phone implements Camera,player
{
 
    @Override
    public void click() {
        System.out.println("Take a Selfi");
    }
 
    @Override
    public void record() {
        System.out.println("Take a video");
    }
 
    @Override
    public void play() {
        System.out.println("Play Music");
    }
 
    @Override
    public void pause() {
        System.out.println("Pause Music");
    }
 
    @Override
    public void stop() {
        System.out.println("Stop Music");
    }
}
 
public class interfaceDemo2 {
    public static void main(String[] args) {
        SmartPhone o =new SmartPhone();
        o.voiceCall();
        o.sms();
        o.click();
        o.record();
        o.play();
        o.pause();
        o.stop();
    }
}
 

Output

Make VoiceClass
We Can send SMS
Take a Selfi
Take a video
Play Music
Pause Music
Stop Music
To download raw file Click Here

Basic Programs