NCERT Solutions Class 12 Computer Science Constructors and Destructors

NCERT solutions for class 12 Constructors and Destructors is given here. To solve the questions related to constructors and destructors in CBSE class 12 board exams students must understand what is a constructor and what is a destructor.

Constructor

Whenever an instance of the class is created the constructor method is called. A constructor is a special member function which enables an object to initialize itself at the time of its creation.

Syntax for declaring constructor

class class_name

{

int h, i;

public:

class_name(void); // Constructor Declared

. . .

};

class_name :: class_name()

{

h=1; i=2; // Constructor defined

}

Types of Constructures

  • Do nothing constructor
  • Default constructor
  • Parameterized constructor
  • Copy constructor

Destructor

As the name suggests, a destructor is used to destroy the objects created by the constructors within the program. To name of a destructor is same as that of a constructor but it is preceded by a tilde (~) sign.

Example:

~Student

{

}

Visit the link to download free solutions for NCERT class 12 constructors and destructors PDF.

Download NCERT Solutions for Class 12 Computer Science Constructors and Destructors

Leave Your Answer