SlideShare a Scribd company logo
5
Most read
7
Most read
11
Most read
Constructor and Types of Constructors
Topic
Constructor and Types of Constructor
Contain
• Overview of Constructor
• Properties of Constructor
• Types of Constructor
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Constructor
• A constructor is a “special” member function which initializes the
objects of class.
Properties of Constructor
• Constructor is invoked automatically whenever an object of class is created.
• Constructor name must be same as class name.
• Constructors should be declared in the public section because private
constructor cannot be invoked
• outside the class so they are useless.
• Constructors do not have return types and they cannot return values, not
even void.
• Constructors cannot be inherited, even though a derived class can call the
base class constructor.
• Constructors cannot be virtual.
• An object with a constructor cannot be used as a member of a union.
• They make implicit calls to the operators new and delete when memory
allocation is required.
Types of Constructors
• There are mainly three types of constructors as follows:
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Default Constructor
• Default constructor is the one which invokes by default when
object of the class is created.
• It is generally used to initialize the value of the data members.
• It is also called no argument constructor.
Example
class integar
{
int m,n;
public:
integer() // Default constructor
{
m=n=0;
}
};
Parameterized Constructor
• Constructors that can take arguments are called parameterized
constructors.
• Sometimes it is necessary to initialize the various data elements of
different objects with different values when they are created.
• We can achieve this objective by passing arguments to the
constructor function when the objects are created.
Example
class integer
{
int m,n;
public:
integer(int x,int y) // Parameterized constructor
{
m =x;
n=y;
}
};
Copy Constructor
• A copy constructor is used to declare and initialize an object from
another object.
• For example, integer(integer &i); OR integer I2(I1);
• Constructor which accepts a reference to its own class as a
parameter is called copy constructor.
Example
class integer
{
int m, n;
public:
integer(rectangle &x) // Copy constructor
{
m = x.m;
n = x.n;
}
};
References
Thank You
#include<iostream>
using namespace std;
int main()
{
cout << “Thank You”;
return 0;
}

More Related Content

PDF
Constructor and Destructor
PPTX
Constructors in C++
PPTX
PDF
Classes and objects
PPT
C++ classes tutorials
PPTX
OOP Unit 2 - Classes and Object
PPTX
Polymorphism In c++
PDF
Constructors and Destructors
Constructor and Destructor
Constructors in C++
Classes and objects
C++ classes tutorials
OOP Unit 2 - Classes and Object
Polymorphism In c++
Constructors and Destructors

What's hot (20)

PPTX
Static Data Members and Member Functions
PPTX
classes and objects in C++
PPTX
Control statements in c
PPT
Operator Overloading
PPTX
Pointers in C Programming
PPTX
Object Oriented Programming Using C++
PDF
Access specifiers (Public Private Protected) C++
PDF
C++ OOPS Concept
PPTX
Programming in c Arrays
PPT
Class and object in C++
PPTX
Type casting in java
PPTX
Constructor ppt
PPTX
INLINE FUNCTION IN C++
PPTX
Functions in c++
PPTX
Method overloading
PPTX
Structures in c language
PPTX
07. Virtual Functions
PPTX
Classes, objects in JAVA
PPTX
Inline function
PPTX
Multiple inheritance in c++
Static Data Members and Member Functions
classes and objects in C++
Control statements in c
Operator Overloading
Pointers in C Programming
Object Oriented Programming Using C++
Access specifiers (Public Private Protected) C++
C++ OOPS Concept
Programming in c Arrays
Class and object in C++
Type casting in java
Constructor ppt
INLINE FUNCTION IN C++
Functions in c++
Method overloading
Structures in c language
07. Virtual Functions
Classes, objects in JAVA
Inline function
Multiple inheritance in c++
Ad

Similar to Constructor and Types of Constructors (20)

PDF
Constructors destructors
PPTX
Constructor and desturctor
PPTX
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
PDF
Constructors or destructors unit(II).pdf
PPTX
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
PPTX
Constructors in C++.pptx
PPTX
C++Constructors
PDF
Constructor and Destructor.pdf
PPT
Constructor & Destructor
PDF
Constructors and destructors
PPTX
CST 203 Lecture 7.pptx
PPT
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
PPT
constructor-.pptcucfkifkficuvguvucufjfugugigig
PPTX
DHARANI.pptx
PPTX
constructocvbcvbcvbcvbr-Destructor (1).pptx
PPTX
Constructor & destructor
PPTX
Constructor and Destructor
DOCX
Constructor-Types of Constructor:default,parameterized,copy constructor-Destr...
PPT
Constructor and destructor in C++
PPT
Constructors and destructors in C++ part 2
Constructors destructors
Constructor and desturctor
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
Constructors or destructors unit(II).pdf
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
Constructors in C++.pptx
C++Constructors
Constructor and Destructor.pdf
Constructor & Destructor
Constructors and destructors
CST 203 Lecture 7.pptx
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
constructor-.pptcucfkifkficuvguvucufjfugugigig
DHARANI.pptx
constructocvbcvbcvbcvbr-Destructor (1).pptx
Constructor & destructor
Constructor and Destructor
Constructor-Types of Constructor:default,parameterized,copy constructor-Destr...
Constructor and destructor in C++
Constructors and destructors in C++ part 2
Ad

More from Dhrumil Panchal (20)

PPTX
YouTube Cryptocurrency Scam
PPTX
This and Static Keyword
PPTX
Servlet and Servlet Life Cycle
PPTX
Properties and Indexers
PPTX
Chomsky Normal Form
PPTX
IEEE 802.11 Architecture and Services
PPTX
Key roles for successful analytic project in Data Mining
PPTX
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
PPTX
Different Software Testing Types and CMM Standard
PPTX
Web Design Issues
PPTX
Toy Interpreter
PPTX
Traditional Problems Associated with Computer Crime
PPTX
Breadth First Search (BFS)
PPTX
Timing Diagram of MVI Instruction of 8085 Microprocessor
PPTX
File Management – File Concept, access methods, File types and File Operation
PPTX
Types of Instruction Format
PPTX
Types of Cables(Guided Media for Transmisson)
PPTX
Global Service for Mobile Communication
PPTX
Denial of Service Attack
PPTX
Fourier Series
YouTube Cryptocurrency Scam
This and Static Keyword
Servlet and Servlet Life Cycle
Properties and Indexers
Chomsky Normal Form
IEEE 802.11 Architecture and Services
Key roles for successful analytic project in Data Mining
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Different Software Testing Types and CMM Standard
Web Design Issues
Toy Interpreter
Traditional Problems Associated with Computer Crime
Breadth First Search (BFS)
Timing Diagram of MVI Instruction of 8085 Microprocessor
File Management – File Concept, access methods, File types and File Operation
Types of Instruction Format
Types of Cables(Guided Media for Transmisson)
Global Service for Mobile Communication
Denial of Service Attack
Fourier Series

Recently uploaded (20)

PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PDF
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PDF
Queuing formulas to evaluate throughputs and servers
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Internship_Presentation_Final engineering.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Structs to JSON How Go Powers REST APIs.pdf
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
Simulation of electric circuit laws using tinkercad.pptx
OOP with Java - Java Introduction (Basics)
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Chapter 6 Design in software Engineeing.ppt
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
Queuing formulas to evaluate throughputs and servers
CH1 Production IntroductoryConcepts.pptx
July 2025: Top 10 Read Articles Advanced Information Technology
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Operating System & Kernel Study Guide-1 - converted.pdf
Internship_Presentation_Final engineering.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
anatomy of limbus and anterior chamber .pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx

Constructor and Types of Constructors

  • 3. Contain • Overview of Constructor • Properties of Constructor • Types of Constructor 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor
  • 4. Constructor • A constructor is a “special” member function which initializes the objects of class.
  • 5. Properties of Constructor • Constructor is invoked automatically whenever an object of class is created. • Constructor name must be same as class name. • Constructors should be declared in the public section because private constructor cannot be invoked • outside the class so they are useless. • Constructors do not have return types and they cannot return values, not even void. • Constructors cannot be inherited, even though a derived class can call the base class constructor. • Constructors cannot be virtual. • An object with a constructor cannot be used as a member of a union. • They make implicit calls to the operators new and delete when memory allocation is required.
  • 6. Types of Constructors • There are mainly three types of constructors as follows: 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor
  • 7. Default Constructor • Default constructor is the one which invokes by default when object of the class is created. • It is generally used to initialize the value of the data members. • It is also called no argument constructor.
  • 8. Example class integar { int m,n; public: integer() // Default constructor { m=n=0; } };
  • 9. Parameterized Constructor • Constructors that can take arguments are called parameterized constructors. • Sometimes it is necessary to initialize the various data elements of different objects with different values when they are created. • We can achieve this objective by passing arguments to the constructor function when the objects are created.
  • 10. Example class integer { int m,n; public: integer(int x,int y) // Parameterized constructor { m =x; n=y; } };
  • 11. Copy Constructor • A copy constructor is used to declare and initialize an object from another object. • For example, integer(integer &i); OR integer I2(I1); • Constructor which accepts a reference to its own class as a parameter is called copy constructor.
  • 12. Example class integer { int m, n; public: integer(rectangle &x) // Copy constructor { m = x.m; n = x.n; } };
  • 14. Thank You #include<iostream> using namespace std; int main() { cout << “Thank You”; return 0; }