# data[].attributes.body
Sample Code

# data[].attributes.attachment_link.readable_text
#include<iostream.h>
#include<conio.h>
int count=0;   //count is a global variable
class Dest
{
  public:
	  Dest()
	  {
	   count++;
	   cout<<"memory allocated for the object:"<<count<<endl;
	  }
	  ~Dest()
	   {
	    cout<<"memory de-allocated for the object:"<<count<<endl;
	    count--;
	   }
};
void main()
{
  clrscr();
  Dest d,e,f,g;
  {
     cout<<"entering block!!!!\n";
     Dest h;
  }
  getch();
}

# data[].attributes.body
Demo Program

# data[].attributes.attachment_link.readable_text
#include<iostream.h>
#include<conio.h>
class A
{
  public:
    int x;
    void getx()
    {
     x=10;
    }
};
class B
{
  public:
    int y;
    void gety()
    {
     y=20;
    }
};
class C:public A, public B
{
  public:
    int z;
    void getz()
    {
     z=40;
    }
    void sum()
    {
     cout<<"sum="<<(x+y+z);
    }
};
void main()
{
 clrscr();
 cout<<"MULTIPLE INHERITANCE\n";
 C ob;
 ob.getx();
 ob.gety();
 ob.getz();
 ob.sum();
 getch();
}

# data[].attributes.body
Demo Program

# data[].attributes.attachment_link.readable_text
#include<iostream.h>
#include<conio.h>
class A
{

  public:
	int x;
	void getx()
	{
	 x=10;
	}
};
class B:public A
{

  public:
	int y;
	void gety()
	{
	 y=20;
	}
};
class C:public B
{

  public:
	int z;
	void getz()
	{
	 z=40;
	}
	void sum()
	{
	 cout<<"sum="<<(x+y+z);
	}
};
void main()
{
 clrscr();
 C ob;
 ob.getx();
 ob.gety();
 ob.getz();
 ob.sum();
 getch();
}

# data[].attributes.body
Demo Program

# data[].attributes.attachment_link.readable_text
#include<iostream.h>
#include<conio.h>
class A
{
       int x;
  public:
	void getx()
	{
	 x=10;
	 }
};
class B:public A
{
 int y;
 public:
	void gety()
	{
	 y=20;
	}
	void sum()
	{
	 cout<<"sum="<<(x+y);
	}
};
void main()
{
 clrscr();
 cout<<"SINGLE INHERITANCE EXAMPLE\n";
 B ob;
 ob.getx();
 ob.gety();
 ob.sum();
 getch();
}

# data[].attributes.body
A destructor is a special member function which has the same name as the class-name with a ~ (tilde) symbol.

•  The main use of destructor is to de-allocate memory for the objects

•  It is declared in the public part of the class.

•  It does not return any values

•  It cannot have arguments

•  Destructor is called when a block ends or program ends.

# data[].attributes.body
A copy constructor is used to declare and initialize an object from another object. For example,

Integer I2(I1);

Would define the object I2 and at the same time initialize it to the values of I1. Another kind of statement is

Integer I2 = I1;

The process of initializing through copy constructor is known as copy initialization.

# data[].attributes.body
If a constructor takes arguments then it is called as parameterized constructor.

It is used to initialize instance variables.

Parameterized constructor can be called implicitly or explicitly

# data[].attributes.body
Default constructor is the constructor which has no arguments

Default constructor will be called automatically once the object is created.

By default, C++ compiler creates a default constructor by itself even if we don’t create to reserve memory for the class.

# data[].attributes.body
Default constructor

Parameterized constructor

Copy constructor

# data[].attributes.body
A constructor is a special member function which has the same name as the class-name.

The main use of constructor is to allocate memory for the objects

It is declared in the public part of the class.

It does not return any values

It can have arguments

Default constructor is called when an object is created

Constructor can be called implicitly or explicitly