q2-polymorphism

package mypackage3;
/*
*
Illustrate a mechanism where you can provide a behavior for opening a door,
window, bank account, conversation, box etc.
*/

class Door
{
public void openDoor()
{
System.out.println(“OPENING A DOOR”);

}
}

class Window
{
public void openWindow()
{
System.out.println(“OPENING A WINDOW”);
}
}

class Bank_Account
{
public void openBank_Account()
{
System.out.println(“OPENING A Account”);
}
}

public class Behavior
{
public Behavior()
{
}
public void open(Door d)
{
d.openDoor();
}
public void open(Window w)
{
w.openWindow();
}
public void open(Bank_Account ba)
{
ba.openBank_Account();
}
public static void main(String[] args)
{
Behavior behavior = new Behavior();
Door d=new Door();
Window w= new Window();
Bank_Account ba=new Bank_Account();
behavior.open(d);
behavior.open(w);
behavior.open(ba);

}
}

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a comment