Difference Between Class And Structure

This blog defines the difference between Class and Structure.

Class

  1. Class is a reference type and its object is created on the heap memory.
     
  2. Class can inherit the another class.
     
  3. Class can have the all types of constructor and destructor.
     
  4. The member variable of class can be initialized directly.
     
  5. class object can not be created without using the new keyword, it means we have to use it.

    Demo obj=new Demo();

Structure

  1. Structure is a value type that is why its object is created on the stack memory.
     
  2. Structure does not support the inheritance.
     
  3. Structure can only have the parametrized constructor. it means a structure can not have the non-parametrized constructor,default constructor and destructor also.
     
  4. The member variable of structure can not be initialized directly.
     
  5. Structure object can be created without using the new keyword.(optional)

    Demo obj;
Ebook Download
View all
Learn
View all