Classes and Objects with Constructors/Destructors: Introduction, Objectives and Class

Get unlimited access to the best preparation resource for IAS : Get complete video lectures from top expert with unlimited validity: cover entire syllabus, expected topics, in full detail- anytime and anywhere & ask your doubts to top experts.

Download PDF of This Page (Size: 290K)

Image of constructors and destructors

Image of Constructors and Destructors

Image of constructors and destructors


  • In object-oriented programming, the emphasis is on data rather than function.

  • Constructor is a specially designed class and destructor returns the memory addresses back to the system.


  • After going through this lesson, you would be able to

  • Define class and object l access the members of the class

  • Learn about three visibility modes: public, private and protected

  • Familiarize with constructor and its types

  • Define constructor with default arguments

  • Use destructor.


  • A class is way to bind the data and its associated functions together. It allows data functions to be hidden, if necessary, from external use.

  • A class specification has two parts.

    • Class declaration

    • Class function definitions

The general format of a class declaration is


  • The keyword class is followed by the name of the class. The body of the class is enclosed between braces and terminated by semi-colon.

  • The class body contains the declaration of variables and functions. These are collectively called members.

  • The variables declared inside the class are called data members.

  • The functions are known as member functions. The keywords public, private and protected are called visibility modes.

  • The use of keyword private is optional.

  • By default, the members of a class are private. If the labels are missing, members are private by default.

  • Such a class is completely hidden from outside world and does not serve any function.

Developed by: