Define an interface Controllable containing two functions- start() and stop(). Define 2 classes Television and Game that implements Controllable interface with other details. Call the functions using variable Controllable.
source file name: LockDemo.java
// interfaceControllable have start (),stop () abstract methods
interface Controllable
{
public void start();
public void stop();
}
// implementation of Controllable interface
class Television implements Controllable
{
public void start()
{
System.out.println ("Television start()");
}
public void stop()
{
System.out.println("Television stop()");
}
}
// implementation of Controllable interface
class Game implements Controllable
{
public void start()
{
System.out.println("Game start()");
}
public void stop()
{
System.out.println("Game stop()");
}
}
class LockDemo
{
public static void main(String ad[])
{
Television t=new Television();
t.start();
t.stop();
Game g=new Game();
g.start();
g.stop();
}
}
0 Comments
Post a Comment