Developer community
+4 votes
60.4k views
asked by
edited by | 60.4k views

3 Answers

0 votes
Best answer

Constructor:

  • Constructor is Used to Initialize the Object.
  • Constructor can takes arguments.
  • Constructor overloading can be possible means more than one constructors can be defined insame class.
  • Constructor has same name as class name.
  • Syntax of constructor:

                class class_name
                  {
                     clas_sname(){}
                     class_name(argulist){}
                 } ;

 

  • Constructor are of following:

               1)Default Constructor.
               2)Parameterized Constructor.
               3)Copy Constructor.
 

  • Constructors can be used to dynamically initialize the memory.
  • Constructor indirectly use the New operator to initialize the object.


Destructor:

  • Destructor is used to destroy the object that are created in memory previously.
  • Destructor can not take any arguments.
  • Destructor overloading can not be possible.
  • Destructor has same name as class name with tiled operator.
  • Syntax of Destructor:

                 class class_name
                   {

                       ~class-name(void){}
                   };
 

  • Destructor has no any types.
  • Destructor can be used to deallocate the memory.
  • Destructor indirectly use the Delete operator to destroy the object initialize by constructor.
     
answered by Sr Member (3.6k points) 2 5
really nice explanation n to the point....
Thank for the difference but can you please tell what are the similarities between them?
Its a very2 good explanation  thanks for your  write difference between  i am very appreciate to u sir
Both have the name of the class .
Both have no return type.
References and pointers cannot be used in constructors and destructors
Thank's for this. it is  really very helpful.......
0 votes
the main difference is that constructor constructs the values of an object and aA destructor destructs the values created by the constructor for the object.
answered by
very simple and important answers !! thnks a lot !
Thank u so much my frnd...
thanks!!! very simple Nd easy explanation.
good!!1
helped me a lottt!!!!!!
Thanks ......:)
0 votes
* A constructor is called when you want to create a new instance of a class. A destructor is called when you want to free up the memory of an object (when you delete it).

 * A constructor constructs the value of an object . A destructor destructs the value created by the constructor for the object.

    Another differentiation is their syntax's :

constructor :

<Class_name>(Arguments)

{

//body of constructor.

}



destructor :

~<class_name>()

{

}
answered by
** constructor  IS CALLED IN THE BEGINNING OF THE PROGRAMM AND **DESTRUCTOR IS CALLED AT THE ENDING OF THE PROGRAM.

**CONSTRUCTER CAN BE OVERLOADED
**DESTROCTER CN NOT BE OVERLOADED

Related questions

+1 vote
2 answers
0 votes
1 answer
asked by anonymous | 103 views
+1 vote
1 answer
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

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,754 questions
4,046 answers
117 comments
10,709 users