How To Implement Dynamic Binding In Java
Rate this article
0 out of 5
In this tutorial we will show you how to implement dynamic bynding in java. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.


Source Code
Dynamic Binding.java
//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'
}
}


Source Code

About The Author
TekTips Videos

Number Of articles Posted
27
Number Of Messages Posted
0
Joined Date
04/02/2013
   
Author
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android