//program to illustrate concept of Dynamic Binding
import java.io.*;
//creating base class
class Base
{
int acno;
String place;
String name;
Base()//Empty constructor
{
}
Base(int a,String n,String p)
{
acno=a;
name=n;
place=p;
}
void display()
{
System.out.println("Personal Profile");
System.out.println("Account No :"+acno);
System.out.println("Name :"+name);
System.out.println("Place :"+place);
}
}
//Another class inherits 'Base' which also has display() function
class Derived extends Base
{
int amt;
String type;
Derived(int a,String n,String p,int am,String ty)
{
//pass values to base class constructor
super(a,n,p);
amt=am;
type=ty;
}
void display()
{
System.out.println("Account Profile");
System.out.println("Amount :"+amt);
System.out.println("Type :"+type);
}
}
//creating new class
class DynamicBindEx
{
public static void main(String args[])
{
//creating objects and initialising
Derived d=new Derived(101,"Sona","Tvm",40000,"Savings");
Base b=new Base(101,"Sona","Tvm");
//create reference of base class
Base r;
r=b;//Assign object of 'Base' to r
r.display();//calls display()of 'Base'
d.display();//calls display() of 'Derived'
}
}