SlideShare a Scribd company logo
09/04/131 VIT - SCSE
1. The derived class need not have a constructor as long as
the base class has a no-argument constructor.
2. However, if the base class has constructors with
arguments (one or more), then it is mandatory for the
derived class to have a constructor and pass the
arguments to the base class constructor.
3. When an object of a derived class is created, the
constructor of the base class is executed first and later the
constructor of the derived class.
Constructors in Derived Classes
09/04/132 VIT - SCSE
1. No constructors in the base class and derived class
2. Constructor only in the base class
class A
{
public:
A()
{
cout<<”No-argument constructor of the base class B is executed”;
}
};
class B:public A
{
public:
};
void main()
{
B ob; //accesses base constructor
}
Constructors in Derived Classes
09/04/133 VIT - SCSE
3. Constructor only in the derived class
class A
{
public:
};
class B:public A
{
public:
B()
{
cout<<”No-argument constructor of the base class B is executed”;
}
};
void main()
{
B ob; //accesses derived constructor
}
09/04/134 VIT - SCSE
4. Constructors in both base and derived classes
class A
{
public:
A()
{
cout<<”No-argument constructor of the base class A executed first”;
}
};
class B:public A
{
public:
B()
{
cout<<”No-argument constructor of the base class B is executed next”;
}
};
void main()
{
B ob; //accesses both constructor
}
09/04/135 VIT - SCSE
class A
{
public:
A()
{
cout<<”No argument constructor of
base class A”;
}
A(int a)
{
cout<<”One argument constructor of
the base class A”;
}
};
class B:public A
{
public:
B(int a)
{
cout<<”One argument
constructor of the
derived class B”;
}
};
void main()
{
B ob(3);
}
5. Multiple constructors in base class and a single
constructor in derived class
09/04/136 VIT - SCSE
Output:
No argument constructor of base class A
One argument constructor of the derived class B
09/04/137 VIT - SCSE
class A
{
public:
A(int a)
{
cout<<”One argument constructor of the base
class A”;
} };
class B:public A
{
public:
B(int a)
{
cout<<”One argument constructor of the
derived class B”;
} };
void main()
{
B ob(3);
}
Output:
Error
6. Constructor in base and derived classes without default
constructor
09/04/138 VIT - SCSE
class A
{
public:
A(int a)
{
cout<<”One argument constructor of
the base class A”;
}};
class B:public A
{
public:
B(int a):A(a)
{
cout<<”One argument constructor of
the derived class B”;
}};
void main()
{
B ob(3);
}
Output:
One argument
constructor of the
base class A
One argument
constructor of the
derived class B
7. Explicit invocation in the absence of default constructor
09/04/139 VIT - SCSE
class A1
{
public:
A1()
{
cout<<”No-argument constructor of the base
class A1”;
}};
class A2
{
public:
A2()
{
cout<<”No argument constructor of the base
class A2”;
}};
class B:public
A2,public A1
{
public:
B()
{
cout<<”No argument
constructor of the
derived class B”;
}};
void main()
{
B ob;
}
8. Constructor in a multiple inherited class with default
invocation
09/04/1310 VIT - SCSE
Output:
No argument constructor of the base class A2
No-argument constructor of the base class A1
No argument constructor of the derived class B
09/04/1311 VIT - SCSE
class A1
{
public:
A1()
{
cout<<”No-argument constructor of the base
class A1”;
}};
class A2
{
public:
A2()
{
cout<<”No argument constructor of the base
class A2”;
}};
class B:public
A2,public A1
{
public:
B():A2(),A1()
{
cout<<”No argument
constructor of the
derived class B”;
}};
void main()
{
B ob;
}
9. Constructor in a multiple inherited class with explicit
invocation
09/04/1312 VIT - SCSE
Output:
No argument constructor of the base class A2
No-argument constructor of the base class A1
No argument constructor of the derived class B
09/04/1313 VIT - SCSE
class A
{
public:
A1()
{
cout<<”No-argument constructor of the base
class A”;
}
};
class B:public A
{
public:
B()
{
cout<<”No argument constructor of the base
class B”;
}
};
class C:public B
{
public:
C()
{
cout<<”No argument
constructor of the
derived class C”;
}
};
void main()
{
C ob;
}
10. Constructor in multilevel inheritance
09/04/1314 VIT - SCSE
Output:
No argument constructor of the base class A
No-argument constructor of the base class B
No argument constructor of the derived class C
09/04/1315 VIT - SCSE
Destructors in derived classes
1.Unlike constructors, destructors in the class hierarchy
(parent and child class) are invoked in the reverse order of
the constructor invocation.
2.The destructor of that class whose constructor was
executed last, while building object of the derived class, will
be executed first whenever the object goes out of scope.
09/04/1316 VIT - SCSE
class B1
{
public:
B1()
{
cout<<”No argument constructor of the base
class B1”;
}
~B1()
{
cout<<”Destructor in the base class B1”;
}};
class B2
{
public:
B2()
{
cout<<”No argument constructor of the base
class B2”;
}
~B2()
{
cout<<”Destructor in the
base class B2”;
}
};
class D:public B1,public
B2
{
public:
D()
{
cout<<”No argument
constructor of the
derived class D”;
}
09/04/1317 VIT - SCSE
~D()
{
cout<<”Destructor in the
derived class D”;
}
};
void main()
{
D ob;
}
Output:
No argument constructor of the base
class B1
No argument constructor of the base
class B2
No argument constructor of the derived
class D
Destructor in the derived class D
Destructor in the base class B2
Destructor in the base class B1
Ad

More Related Content

What's hot (20)

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java ppt
kunal kishore
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
RubaNagarajan
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Templates
TemplatesTemplates
Templates
Pranali Chaudhari
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
Amit Trivedi
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Java packages
Java packagesJava packages
Java packages
BHUVIJAYAVELU
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java ppt
kunal kishore
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
Amit Trivedi
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 

Viewers also liked (20)

Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
Abhishek Pratap
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
myrajendra
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
harshaltambe
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
Michael Heron
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
adil raja
 
Some Basic Concepts of Object Oriented Methodology
Some Basic Concepts of Object Oriented MethodologySome Basic Concepts of Object Oriented Methodology
Some Basic Concepts of Object Oriented Methodology
Manoj Kumar
 
Friend functions
Friend functions Friend functions
Friend functions
Megha Singh
 
Object oriented methodology & unified modeling language
Object oriented methodology & unified modeling languageObject oriented methodology & unified modeling language
Object oriented methodology & unified modeling language
Ismail El Gayar
 
Container ship
Container ship Container ship
Container ship
Hassan Moursy
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
Templates
TemplatesTemplates
Templates
Nilesh Dalvi
 
Inheritance
InheritanceInheritance
Inheritance
Srinath Dhayalamoorthy
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++
elliando dias
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
ForwardBlog Enewzletter
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
Abhishek Pratap
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
myrajendra
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
harshaltambe
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
Michael Heron
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
adil raja
 
Some Basic Concepts of Object Oriented Methodology
Some Basic Concepts of Object Oriented MethodologySome Basic Concepts of Object Oriented Methodology
Some Basic Concepts of Object Oriented Methodology
Manoj Kumar
 
Friend functions
Friend functions Friend functions
Friend functions
Megha Singh
 
Object oriented methodology & unified modeling language
Object oriented methodology & unified modeling languageObject oriented methodology & unified modeling language
Object oriented methodology & unified modeling language
Ismail El Gayar
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++
elliando dias
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Ad

Similar to 11 constructors in derived classes (20)

Inheritance_PART2.pptx
Inheritance_PART2.pptxInheritance_PART2.pptx
Inheritance_PART2.pptx
ArjunArora78
 
Constructors.16
Constructors.16Constructors.16
Constructors.16
myrajendra
 
Inheritance
InheritanceInheritance
Inheritance
poonam.rwalia
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projeto
lcbj
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
ssuser6f3c8a
 
C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)
Ananda Kumar HN
 
7 class objects
7 class objects7 class objects
7 class objects
Docent Education
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Laxman Puri
 
object oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptxobject oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptx
WasiqAslam1
 
Lecturespecial
LecturespecialLecturespecial
Lecturespecial
karan saini
 
OOP
OOPOOP
OOP
karan saini
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
Javier Gonzalez-Sanchez
 
Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)
Abhishek Khune
 
Lab3
Lab3Lab3
Lab3
karan saini
 
OOP unit II inheritance.pptx object oriented programming
OOP unit II inheritance.pptx object oriented programmingOOP unit II inheritance.pptx object oriented programming
OOP unit II inheritance.pptx object oriented programming
Srishti951154
 
6. Virtual base class.pptx and virtual function
6. Virtual base class.pptx and virtual function6. Virtual base class.pptx and virtual function
6. Virtual base class.pptx and virtual function
archana22486y
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
Docent Education
 
Constructor
ConstructorConstructor
Constructor
abhay singh
 
Inheritance_PART2.pptx
Inheritance_PART2.pptxInheritance_PART2.pptx
Inheritance_PART2.pptx
ArjunArora78
 
Constructors.16
Constructors.16Constructors.16
Constructors.16
myrajendra
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projeto
lcbj
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
ssuser6f3c8a
 
C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)C++ prgms 5th unit (inheritance ii)
C++ prgms 5th unit (inheritance ii)
Ananda Kumar HN
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Laxman Puri
 
object oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptxobject oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptx
WasiqAslam1
 
Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)
Abhishek Khune
 
OOP unit II inheritance.pptx object oriented programming
OOP unit II inheritance.pptx object oriented programmingOOP unit II inheritance.pptx object oriented programming
OOP unit II inheritance.pptx object oriented programming
Srishti951154
 
6. Virtual base class.pptx and virtual function
6. Virtual base class.pptx and virtual function6. Virtual base class.pptx and virtual function
6. Virtual base class.pptx and virtual function
archana22486y
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
Ad

More from Docent Education (13)

17 files and streams
17 files and streams17 files and streams
17 files and streams
Docent Education
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
Docent Education
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
Docent Education
 
13 exception handling
13 exception handling13 exception handling
13 exception handling
Docent Education
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
Docent Education
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
Docent Education
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
Docent Education
 
5 array
5 array5 array
5 array
Docent Education
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
Docent Education
 
1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented Programming
Docent Education
 
3 intro basic_elements
3 intro basic_elements3 intro basic_elements
3 intro basic_elements
Docent Education
 
2 Intro c++
2 Intro c++2 Intro c++
2 Intro c++
Docent Education
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
Docent Education
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 

11 constructors in derived classes

  • 1. 09/04/131 VIT - SCSE 1. The derived class need not have a constructor as long as the base class has a no-argument constructor. 2. However, if the base class has constructors with arguments (one or more), then it is mandatory for the derived class to have a constructor and pass the arguments to the base class constructor. 3. When an object of a derived class is created, the constructor of the base class is executed first and later the constructor of the derived class. Constructors in Derived Classes
  • 2. 09/04/132 VIT - SCSE 1. No constructors in the base class and derived class 2. Constructor only in the base class class A { public: A() { cout<<”No-argument constructor of the base class B is executed”; } }; class B:public A { public: }; void main() { B ob; //accesses base constructor } Constructors in Derived Classes
  • 3. 09/04/133 VIT - SCSE 3. Constructor only in the derived class class A { public: }; class B:public A { public: B() { cout<<”No-argument constructor of the base class B is executed”; } }; void main() { B ob; //accesses derived constructor }
  • 4. 09/04/134 VIT - SCSE 4. Constructors in both base and derived classes class A { public: A() { cout<<”No-argument constructor of the base class A executed first”; } }; class B:public A { public: B() { cout<<”No-argument constructor of the base class B is executed next”; } }; void main() { B ob; //accesses both constructor }
  • 5. 09/04/135 VIT - SCSE class A { public: A() { cout<<”No argument constructor of base class A”; } A(int a) { cout<<”One argument constructor of the base class A”; } }; class B:public A { public: B(int a) { cout<<”One argument constructor of the derived class B”; } }; void main() { B ob(3); } 5. Multiple constructors in base class and a single constructor in derived class
  • 6. 09/04/136 VIT - SCSE Output: No argument constructor of base class A One argument constructor of the derived class B
  • 7. 09/04/137 VIT - SCSE class A { public: A(int a) { cout<<”One argument constructor of the base class A”; } }; class B:public A { public: B(int a) { cout<<”One argument constructor of the derived class B”; } }; void main() { B ob(3); } Output: Error 6. Constructor in base and derived classes without default constructor
  • 8. 09/04/138 VIT - SCSE class A { public: A(int a) { cout<<”One argument constructor of the base class A”; }}; class B:public A { public: B(int a):A(a) { cout<<”One argument constructor of the derived class B”; }}; void main() { B ob(3); } Output: One argument constructor of the base class A One argument constructor of the derived class B 7. Explicit invocation in the absence of default constructor
  • 9. 09/04/139 VIT - SCSE class A1 { public: A1() { cout<<”No-argument constructor of the base class A1”; }}; class A2 { public: A2() { cout<<”No argument constructor of the base class A2”; }}; class B:public A2,public A1 { public: B() { cout<<”No argument constructor of the derived class B”; }}; void main() { B ob; } 8. Constructor in a multiple inherited class with default invocation
  • 10. 09/04/1310 VIT - SCSE Output: No argument constructor of the base class A2 No-argument constructor of the base class A1 No argument constructor of the derived class B
  • 11. 09/04/1311 VIT - SCSE class A1 { public: A1() { cout<<”No-argument constructor of the base class A1”; }}; class A2 { public: A2() { cout<<”No argument constructor of the base class A2”; }}; class B:public A2,public A1 { public: B():A2(),A1() { cout<<”No argument constructor of the derived class B”; }}; void main() { B ob; } 9. Constructor in a multiple inherited class with explicit invocation
  • 12. 09/04/1312 VIT - SCSE Output: No argument constructor of the base class A2 No-argument constructor of the base class A1 No argument constructor of the derived class B
  • 13. 09/04/1313 VIT - SCSE class A { public: A1() { cout<<”No-argument constructor of the base class A”; } }; class B:public A { public: B() { cout<<”No argument constructor of the base class B”; } }; class C:public B { public: C() { cout<<”No argument constructor of the derived class C”; } }; void main() { C ob; } 10. Constructor in multilevel inheritance
  • 14. 09/04/1314 VIT - SCSE Output: No argument constructor of the base class A No-argument constructor of the base class B No argument constructor of the derived class C
  • 15. 09/04/1315 VIT - SCSE Destructors in derived classes 1.Unlike constructors, destructors in the class hierarchy (parent and child class) are invoked in the reverse order of the constructor invocation. 2.The destructor of that class whose constructor was executed last, while building object of the derived class, will be executed first whenever the object goes out of scope.
  • 16. 09/04/1316 VIT - SCSE class B1 { public: B1() { cout<<”No argument constructor of the base class B1”; } ~B1() { cout<<”Destructor in the base class B1”; }}; class B2 { public: B2() { cout<<”No argument constructor of the base class B2”; } ~B2() { cout<<”Destructor in the base class B2”; } }; class D:public B1,public B2 { public: D() { cout<<”No argument constructor of the derived class D”; }
  • 17. 09/04/1317 VIT - SCSE ~D() { cout<<”Destructor in the derived class D”; } }; void main() { D ob; } Output: No argument constructor of the base class B1 No argument constructor of the base class B2 No argument constructor of the derived class D Destructor in the derived class D Destructor in the base class B2 Destructor in the base class B1
  翻译: