search
Log In
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
1 vote
109 views
How is the order of invocation of destructors different from constructors?
in Object Oriented Programming 109 views

1 Answer

3 votes
 
Best answer

Order of Constructor Invocation is Base Class then Derived Class

While order of Destructor Invocation is Derived Class and then Base Class

However, this can be understood diagrammatically as below:

A Derived class is a specialization of a Base Class. This is means some features are added or modified in the specialized (Derived) class.

  • To construct above diagram, I would first construct inner box (base class) and then construct outer box (derived class). That is why Base class constructor is invoked before the derived class constructor
  • And when I have to erase (destruct) the diagram, I will first erase the outer box (derived class) and then erase the inner box (base class). That is why Derived class destructor is invoked before base class destructor

selected by

Related questions

0 votes
1 answer
1
83 views
What is meant by object slicing?
asked May 27, 2017 in Programming iarnav 83 views
0 votes
2 answers
2
117 views
What is meant by precedence rule for evaluation of expressions?
asked May 27, 2017 in Programming iarnav 117 views
0 votes
1 answer
3
74 views
What are structured languages and what are their major features?
asked May 27, 2017 in Programming iarnav 74 views
0 votes
1 answer
4
89 views
Consider a pointer declaration int i=10,*p; p=&x; Is p – – ; a valid statement, justify? explain in as simple way as possible.
asked May 27, 2017 in Programming iarnav 89 views
...