SlideShare a Scribd company logo
12
Most read
14
Most read
15
Most read
Constructor and Destructor in OOP
Qazi Abdul Samad
Presented By
Contends
Constructor
Concept of Constructor in OOP
Characteristic of Constructor
Types of Constructor
Constructor Overloading
Destructor
Charactersticks of Destructor
Concept of Destructor in OOP
Difference Between Constructor and Destructor
Constructor
 Constructor is a special type of method that is invoked when
you create a new instance of a class.
 constructor is used to initialize the members of the class.the
name of the constructor is same as the name of the class that
contains it.
Concept of Constructor in OOP
 A constructor is a special member function whose task to
initialize the object of that class.
 it is speacial because its name is the same as the class name.
 constructor is invoked whenever an object of the associated is
class is created.
 it is called constructor because it construct the values of data
member of the class.
Characteristic of Constructor
 They cannot be inherited, though a derived class can call the base
class constructor.
 Like other C++ functions, Constructors can have default
arguments.
 Constructors can not be virtual.
 We can not refer to their addresses.
 They make ‘implicit calls’ to the operators new and delete when
memory allocation is required.
Types of Constructor
1. Default Constructor :
A constructor that accepts no parameters is called
Default Constructor.
2. Parameterized Constructor :
The constructor that can take arguments is called as
Parameterized Constructor.
3. Copy Constructor :
A constructor can accept a reference to its own class
as a parameter which is called Copy Constructor
Example of Default Constructor ;
Example of Parameterized
constructor ;
Example of Copy constructor;
Constructor Overloading
 The process of declaring multiple constructor with the same
name but different parameters is known as constructor
overloading.
 the constructor with same name must differ in one of the
following ways
1. number of parameters
2. type of parameters
3. sequence of parameters
 its covenient to be able to gives values to member variables of
a class when the objects is created.
Example
Destructor
A destructor, as the name implies is used to destroy the objects
that have been created by a constructor.
Like a constructor the destructor is also a special member
function whose name is the same as the class name but is
preceded by a tilde (~).
A destructor never takes any argument nor does it return any
value.
Example the destructor for the class integer can be defined as
shown below
~integer( ) { }
Example of Destructor
Characteristic OF Destructor
 Destructor function are invoked automatically when the objects
are destroyed.
 if the class has a destructor each object of that class will be de-
intialized before the objects goes out of scope.
 destructor function obeys the usual access rules.
 no arrguments can be provided to a destructor neither does it
returns any value.
 they can not be inherited.
 a destructor may not be static..
Difference Between Constructor &
Destructor
The End
Thank u !

More Related Content

PPTX
constructors in java ppt
PPTX
Constructor in java
PPTX
Interface in java
PPTX
Static Data Members and Member Functions
PPTX
oops concept in java | object oriented programming in java
PPTX
Method overloading
PDF
Function overloading ppt
PPTX
Constructor in java
constructors in java ppt
Constructor in java
Interface in java
Static Data Members and Member Functions
oops concept in java | object oriented programming in java
Method overloading
Function overloading ppt
Constructor in java

What's hot (20)

PPTX
Function overloading and overriding
PPT
Inheritance in java
PPTX
classes and objects in C++
PDF
Memory Management C++ (Peeling operator new() and delete())
PPT
Function overloading(c++)
PDF
Arrays in Java
PPTX
Pure virtual function and abstract class
PPTX
Constructors in C++
PPTX
Inline function
PDF
Generics
PPTX
Inheritance in java
PDF
itft-Decision making and branching in java
PPT
Operator Overloading
PPT
friend function(c++)
PPTX
Java constructors
PPTX
Super Keyword in Java.pptx
PPTX
Constants in java
PDF
Java I/o streams
PDF
Java variable types
PPTX
String, string builder, string buffer
Function overloading and overriding
Inheritance in java
classes and objects in C++
Memory Management C++ (Peeling operator new() and delete())
Function overloading(c++)
Arrays in Java
Pure virtual function and abstract class
Constructors in C++
Inline function
Generics
Inheritance in java
itft-Decision making and branching in java
Operator Overloading
friend function(c++)
Java constructors
Super Keyword in Java.pptx
Constants in java
Java I/o streams
Java variable types
String, string builder, string buffer
Ad

Similar to Constructor and destructor in oop (20)

PPT
constructor and destructor-object oriented programming
PPTX
Constructor and Destructor
PPTX
Constructor and Destructor in c++
PPTX
DHARANI.pptx
PPTX
Constructor & destructor based question- cbse cs class 12th
PPTX
Constructor and desturctor
PPTX
An introduction to Constructors and destructors in c++ .pptx
PPTX
C++ Unit-III Lecture-3a-C++ Programming Concepts
PPTX
Constructors in C++.pptx
PPTX
PPT
Oop Constructor Destructors Constructor Overloading lecture 2
PPTX
Constructor & destructor
PDF
Constructor and Destructor.pdf
PPTX
Constructors and Destructors
PPTX
What is Constructors and Destructors in C++ (Explained with Example along wi...
PDF
1.11 Constructors and Destructors....pdf
PPTX
Destructors
PPTX
C++ basic
PPT
ConsTRUCTION AND DESTRUCTION
constructor and destructor-object oriented programming
Constructor and Destructor
Constructor and Destructor in c++
DHARANI.pptx
Constructor & destructor based question- cbse cs class 12th
Constructor and desturctor
An introduction to Constructors and destructors in c++ .pptx
C++ Unit-III Lecture-3a-C++ Programming Concepts
Constructors in C++.pptx
Oop Constructor Destructors Constructor Overloading lecture 2
Constructor & destructor
Constructor and Destructor.pdf
Constructors and Destructors
What is Constructors and Destructors in C++ (Explained with Example along wi...
1.11 Constructors and Destructors....pdf
Destructors
C++ basic
ConsTRUCTION AND DESTRUCTION
Ad

Recently uploaded (20)

PPTX
Introduction-to-Food-Packaging-and-packaging -materials.pptx
PPTX
Project and change Managment: short video sequences for IBA
PPTX
Research Process - Research Methods course
PPTX
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PDF
Instagram's Product Secrets Unveiled with this PPT
PDF
Microsoft-365-Administrator-s-Guide_.pdf
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PPTX
water for all cao bang - a charity project
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PPTX
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
PPTX
Self management and self evaluation presentation
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
worship songs, in any order, compilation
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
PDF
Presentation1 [Autosaved].pdf diagnosiss
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
chapter8-180915055454bycuufucdghrwtrt.pptx
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
PDF
COLEAD A2F approach and Theory of Change
Introduction-to-Food-Packaging-and-packaging -materials.pptx
Project and change Managment: short video sequences for IBA
Research Process - Research Methods course
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
2025-08-10 Joseph 02 (shared slides).pptx
Instagram's Product Secrets Unveiled with this PPT
Microsoft-365-Administrator-s-Guide_.pdf
Intro to ISO 9001 2015.pptx wareness raising
water for all cao bang - a charity project
Impressionism_PostImpressionism_Presentation.pptx
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
Self management and self evaluation presentation
The Effect of Human Resource Management Practice on Organizational Performanc...
worship songs, in any order, compilation
Swiggy’s Playbook: UX, Logistics & Monetization
Presentation1 [Autosaved].pdf diagnosiss
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
chapter8-180915055454bycuufucdghrwtrt.pptx
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
COLEAD A2F approach and Theory of Change

Constructor and destructor in oop

  • 1. Constructor and Destructor in OOP Qazi Abdul Samad Presented By
  • 2. Contends Constructor Concept of Constructor in OOP Characteristic of Constructor Types of Constructor Constructor Overloading Destructor Charactersticks of Destructor Concept of Destructor in OOP Difference Between Constructor and Destructor
  • 3. Constructor  Constructor is a special type of method that is invoked when you create a new instance of a class.  constructor is used to initialize the members of the class.the name of the constructor is same as the name of the class that contains it.
  • 4. Concept of Constructor in OOP  A constructor is a special member function whose task to initialize the object of that class.  it is speacial because its name is the same as the class name.  constructor is invoked whenever an object of the associated is class is created.  it is called constructor because it construct the values of data member of the class.
  • 5. Characteristic of Constructor  They cannot be inherited, though a derived class can call the base class constructor.  Like other C++ functions, Constructors can have default arguments.  Constructors can not be virtual.  We can not refer to their addresses.  They make ‘implicit calls’ to the operators new and delete when memory allocation is required.
  • 6. Types of Constructor 1. Default Constructor : A constructor that accepts no parameters is called Default Constructor. 2. Parameterized Constructor : The constructor that can take arguments is called as Parameterized Constructor. 3. Copy Constructor : A constructor can accept a reference to its own class as a parameter which is called Copy Constructor
  • 7. Example of Default Constructor ;
  • 9. Example of Copy constructor;
  • 10. Constructor Overloading  The process of declaring multiple constructor with the same name but different parameters is known as constructor overloading.  the constructor with same name must differ in one of the following ways 1. number of parameters 2. type of parameters 3. sequence of parameters  its covenient to be able to gives values to member variables of a class when the objects is created.
  • 12. Destructor A destructor, as the name implies is used to destroy the objects that have been created by a constructor. Like a constructor the destructor is also a special member function whose name is the same as the class name but is preceded by a tilde (~). A destructor never takes any argument nor does it return any value. Example the destructor for the class integer can be defined as shown below ~integer( ) { }
  • 14. Characteristic OF Destructor  Destructor function are invoked automatically when the objects are destroyed.  if the class has a destructor each object of that class will be de- intialized before the objects goes out of scope.  destructor function obeys the usual access rules.  no arrguments can be provided to a destructor neither does it returns any value.  they can not be inherited.  a destructor may not be static..