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

Constructor And Destructor In Inheritance In C++ | Constructor And Destructor In Inheritance In Hindi

 

Constructor And Destructor In Inheritance

Constructors and destructors depends on the type of inheritance being implemented.

  • Base class constructors are called first and the derived class constructors are called next in single inheritance.
  • Destructor is called in reverse sequence of constructor invocation i.e. The destructor of the derived class is called first and the destructor of the base is called next.
image of constructor and destructor inheritance in c++

Fig:Constructor And Destructor In Inheritance In C++

Program:

#include<iostream.h>

#include<conio.h>

class base()

{

public:

base()

{

cout<<”base class constructor”;

}

~base()

{

cout<<” base class destructor”;

}

};

class derived: public base

{

public:

derived()

{

cout<<”derived class constructor”;

}

~derived()

{

cout<<” derived class destructor”;

}

};

void main()

{

derived ob;

getch();

}

Output:

Base class constructor

Derived class constructor

Base class destructor

Derived class destructor

 

 

 

No comments:

Post a Comment