The Gateway to Computer Science Excellence
+1 vote
90 views
How is the order of invocation of destructors different from constructors?
in Object Oriented Programming by Loyal (8.4k points) | 90 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
by Loyal (5.5k points)
selected by

Related questions

0 votes
1 answer
1
asked May 27, 2017 in Programming by iarnav Loyal (8.4k points) | 75 views
0 votes
2 answers
2
0 votes
1 answer
3
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
50,737 questions
57,321 answers
198,400 comments
105,153 users