TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 24 August 2020

Early binding and Late binding in C++ | Explain Early binding and Late binding in C++ | Define Early binding and Late binding in C++ | Early binding and Late binding in C++ In Hindi

 

Early binding and Late binding in C++


Binding refers to the process of converting identifiers (such as variable and performance names) into addresses. Binding is done for each variable and functions.It takes place either at compile time or at runtime.


image of Early binding and Late binding in C++
Fig: Early binding and Late binding in C++ 

      

      1.   Early Binding (compile-time time polymorphism)

Early binding  as the name indicates, compiler (or linker) directly associate an address to the function call. It replaces the call with a machine language instruction that tells the mainframe to leap to the address of the function. This can be achieved by declaring virtual function.

 
Program:

#include<iostream.h>

#include<conio.h>

class Base

{

public:

 virtual void show()

{

cout<<”base class /n”;

}

};

class Derived: public Base

{

public:

void show()

{

cout<<”derived class /n”

}

};

void main()

{

Base *bp=new Derived;

bp->show();

}


Output:

Base class

 

        2.   Late Binding : (Run time polymorphism) 

In this, the compiler adds code that identifies the kind of object at runtime then matches the call with the right function definition .This can be achieved by declaring virtual function.


Program:

#include<iostream.h>

#include<conio.h>

class Base

{

public:

 virtual void show()

{

cout<<”base class /n”;

}

};

class Derived: public Base

{

public:

void show()

{

cout<<”derived class /n”

}

};

void main()

{

Base *bp=new Derived;

bp->show();

}


Output:

derived class

 

No comments:

Post a Comment