SlideShare a Scribd company logo
1 of 14
Constructors and
Destructors
UNIT - III
CHAPTER – 9
9.1 Introduction
 When a variable is declared , if it is not initialized it contains a garbage value.
 The programmer has to assign value to the variable.
 Initialization prevents variable from containing garbage value.
 An object holds copies of one or more individual data members.
 When an object is created , its data member contains garbage value.
 Declaring the variable as static allows the programmer to initialize member
variables with desired values.
9.1 Introduction
 Drawback of static members is only one copy of static member is created for
entire class , all objects share same copy and does not provide security.
 If when an object is declared as static , all member variables are initialized to
zero.
 Every static object has its own set of member variables .
 Drawback of static object is , contents of object remains throughout the program
occupying more memory space.
 Eg. Book
9.2 Constructors and Destructors
• A separate member function is used for reading input values for data members.
• By using object ,member functions can be invoked and data members are
initialized.
• C++ provides a pair of built-in functions called Constructor and Destructor .
• Constructor - constructs the objects
• Destructor - destroys the objects
• Compiler automatically executes this functions.
• Programmer does not need to invoke the function.
9.2 Constructors and Destructors
 When an object is created , constructor is executed , programmer can also pass
values to constructor to initialize member variables with values.
 Destructor destroys the object , destructor is executed at the end of the function
when objects are of no use.
 Optional to declare constructor and destructor , if not declared compiler executes
implicit constructor and destructor.
 Constructor , Destructor – special member functions , decides how objects of class
are created , initialized , copied and destroyed.
9.2 Constructors and Destructors
• Names are same to name of class they belong to .
• Only difference is that destructor is preceded by ~(tilde) operator.
• Can declare and define them within the class or declare them within the class and define
them outside.
• Destructor is automatically executed when object goes out of scope.
• Also invoked when delete operator is used to free the memory allocated with class
pointer.
• Class can have only one destructor
•9.3 Characteristics of Constructors and Destructors ( Book)
9.5 Constructors with
Arguments(Parameterized Constructor)
• Also possible to create Constructor with arguments and
such Constructors are called parameterized Constructors.
• For that Constructors values must be passed to the
constructor when an object is created
• Eg. Book
9.6 Overloading Constructors
(Multiple Constructors)
• It is also possible to overload Constructors like functions.
• A Class can have more than one Constructor – this is called as Constructor
Overloading
• All constructors are defined with same name to which the class they belong to.
• All constructors contain different number of arguments, depending upon the
number of arguments , compiler executes appropriate constructor
• Eg. Book
9.8 Constructors with Default Arguments
• Like functions ,possible to declare constructors
with default arguments.
• Eg. Book
9.9 Copy Constructors
•Constructor accepts arguments of any data type including user-defined data types ,exclusive of the
class to which it belongs
•Possible to pass reference of object to the constructor-declaration known as copy constructors
9.9 Copy Constructors
• When we pass object by value into a function , a temporary copy of that object
is created
• Copy constructors require one argument , with reference to an object of
that class
• By using copy constructors , possible to declare and initialize one object
using reference of another object
• Whenever a constructor is called , a copy of an object is created.
9.11 Destructors
• Destructors destroy class objects created by constructors
• Destructors have same name as class preceded by tilde(~)
• Destructor only destroys the object and hence it cannot be overloaded
• It does not require any arguments nor returns any value.
• It is automatically called when object goes out of scope
• Destructor releases memory space occupied by the objects
• Eg. Book
9.12 Calling Constructors and Destructors
• Compiler automatically calls the Constructor and Destructor.
• Can call constructor and destructor like normal user –defined
function.
• Calling methods are different for constructors and destructors.
9.16 Dynamic initialization using
Constructors
• After declaring class data member variables , they can be initialized at the time
of program execution using pointers
• This type of initialization of data is called dynamic initialization
• Advantage of dynamic initialization is , it allows different initialization modes
using overloaded constructors
• Pointer variables are used as arguments for constructors
• Eg. Book

More Related Content

What's hot

Java Static Factory Methods
Java Static Factory MethodsJava Static Factory Methods
Java Static Factory MethodsYe Win
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructorrajshreemuthiah
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSeerat Malik
 
Java serialization
Java serializationJava serialization
Java serializationSujit Kumar
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティスUnity Technologies Japan K.K.
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Avoid creating unncessary objects
Avoid creating unncessary objectsAvoid creating unncessary objects
Avoid creating unncessary objectsYe Win
 
Chapter 1 Presentation
Chapter 1 PresentationChapter 1 Presentation
Chapter 1 Presentationguest0d6229
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOPMuhammad Hammad Waseem
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Wekoslav Stefanovski
 

What's hot (20)

Java Static Factory Methods
Java Static Factory MethodsJava Static Factory Methods
Java Static Factory Methods
 
Dagger1
Dagger1Dagger1
Dagger1
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Constructor oopj
Constructor oopjConstructor oopj
Constructor oopj
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
Java serialization
Java serializationJava serialization
Java serialization
 
Generic
GenericGeneric
Generic
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Constructors
ConstructorsConstructors
Constructors
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 
Avoid creating unncessary objects
Avoid creating unncessary objectsAvoid creating unncessary objects
Avoid creating unncessary objects
 
Lesson3
Lesson3Lesson3
Lesson3
 
Chapter 1 Presentation
Chapter 1 PresentationChapter 1 Presentation
Chapter 1 Presentation
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#
 

Similar to Constructors and Destructors

Similar to Constructors and Destructors (20)

constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programming
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
C++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxC++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptx
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Constructor & Destructor
Constructor & DestructorConstructor & Destructor
Constructor & Destructor
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Constructor and destructor in oop
Constructor and destructor in oop Constructor and destructor in oop
Constructor and destructor in oop
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Constructor and desturctor
Constructor and desturctorConstructor and desturctor
Constructor and desturctor
 
C++
C++C++
C++
 
C++
C++C++
C++
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
constructor in object oriented program.pptx
constructor in object oriented program.pptxconstructor in object oriented program.pptx
constructor in object oriented program.pptx
 
constructor.ppt
constructor.pptconstructor.ppt
constructor.ppt
 
Constructors in C++.pptx
Constructors in C++.pptxConstructors in C++.pptx
Constructors in C++.pptx
 
106da session5 c++
106da session5 c++106da session5 c++
106da session5 c++
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
CST 203 Lecture 7.pptx
CST 203 Lecture 7.pptxCST 203 Lecture 7.pptx
CST 203 Lecture 7.pptx
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

Constructors and Destructors

  • 2. 9.1 Introduction  When a variable is declared , if it is not initialized it contains a garbage value.  The programmer has to assign value to the variable.  Initialization prevents variable from containing garbage value.  An object holds copies of one or more individual data members.  When an object is created , its data member contains garbage value.  Declaring the variable as static allows the programmer to initialize member variables with desired values.
  • 3. 9.1 Introduction  Drawback of static members is only one copy of static member is created for entire class , all objects share same copy and does not provide security.  If when an object is declared as static , all member variables are initialized to zero.  Every static object has its own set of member variables .  Drawback of static object is , contents of object remains throughout the program occupying more memory space.  Eg. Book
  • 4. 9.2 Constructors and Destructors • A separate member function is used for reading input values for data members. • By using object ,member functions can be invoked and data members are initialized. • C++ provides a pair of built-in functions called Constructor and Destructor . • Constructor - constructs the objects • Destructor - destroys the objects • Compiler automatically executes this functions. • Programmer does not need to invoke the function.
  • 5. 9.2 Constructors and Destructors  When an object is created , constructor is executed , programmer can also pass values to constructor to initialize member variables with values.  Destructor destroys the object , destructor is executed at the end of the function when objects are of no use.  Optional to declare constructor and destructor , if not declared compiler executes implicit constructor and destructor.  Constructor , Destructor – special member functions , decides how objects of class are created , initialized , copied and destroyed.
  • 6. 9.2 Constructors and Destructors • Names are same to name of class they belong to . • Only difference is that destructor is preceded by ~(tilde) operator. • Can declare and define them within the class or declare them within the class and define them outside. • Destructor is automatically executed when object goes out of scope. • Also invoked when delete operator is used to free the memory allocated with class pointer. • Class can have only one destructor •9.3 Characteristics of Constructors and Destructors ( Book)
  • 7. 9.5 Constructors with Arguments(Parameterized Constructor) • Also possible to create Constructor with arguments and such Constructors are called parameterized Constructors. • For that Constructors values must be passed to the constructor when an object is created • Eg. Book
  • 8. 9.6 Overloading Constructors (Multiple Constructors) • It is also possible to overload Constructors like functions. • A Class can have more than one Constructor – this is called as Constructor Overloading • All constructors are defined with same name to which the class they belong to. • All constructors contain different number of arguments, depending upon the number of arguments , compiler executes appropriate constructor • Eg. Book
  • 9. 9.8 Constructors with Default Arguments • Like functions ,possible to declare constructors with default arguments. • Eg. Book
  • 10. 9.9 Copy Constructors •Constructor accepts arguments of any data type including user-defined data types ,exclusive of the class to which it belongs •Possible to pass reference of object to the constructor-declaration known as copy constructors
  • 11. 9.9 Copy Constructors • When we pass object by value into a function , a temporary copy of that object is created • Copy constructors require one argument , with reference to an object of that class • By using copy constructors , possible to declare and initialize one object using reference of another object • Whenever a constructor is called , a copy of an object is created.
  • 12. 9.11 Destructors • Destructors destroy class objects created by constructors • Destructors have same name as class preceded by tilde(~) • Destructor only destroys the object and hence it cannot be overloaded • It does not require any arguments nor returns any value. • It is automatically called when object goes out of scope • Destructor releases memory space occupied by the objects • Eg. Book
  • 13. 9.12 Calling Constructors and Destructors • Compiler automatically calls the Constructor and Destructor. • Can call constructor and destructor like normal user –defined function. • Calling methods are different for constructors and destructors.
  • 14. 9.16 Dynamic initialization using Constructors • After declaring class data member variables , they can be initialized at the time of program execution using pointers • This type of initialization of data is called dynamic initialization • Advantage of dynamic initialization is , it allows different initialization modes using overloaded constructors • Pointer variables are used as arguments for constructors • Eg. Book