Define an interface Lockable containing functions- open() and close(). Define 2 classes, File and cupboard that implements Lockable interface with other details. Call the functions using the variable of Lockable.

source file name: MediaDemo.java

//interface Lockable have open().close() abstract methods

interface Lockable

{

public void open();

public void close();

}

// implementation of Lockable interface

class File implements Lockable

{

 public void open()

 {

System.out.println("File open()");

 }

public void close()

{

System.out.println ("File close()");

}

}

// implementation of Lockable interface

class Cupboard implements Lockable

{

public void open()

{

System.out.println ("Cupboard open()");

}

public void close()

{

System.out.println ("Cupboard close()");

}

}

class MediaDemo

{

public static void main(String ad [])

{

File f = new File();

f.open () ;

f.close () ;

Cupboard c = new Cupboard() ;

c.open () ;

c.close () ;

}

}

output:

D:\JavaPrograms\InterfacePrgs>javac MediaDemo.java

D:\JavaPrograms\InterfacePrgs>java MediaDemo
File open()
File close()
Cupboard open()
Cupboard close()