Structure

  

                    Class

Structure is a collection of different types of data type Class is a group of common objects that share common properties and relationships.
By default, structure member is public By default, class member is private
Structure is value type so they are stored on stack Class is reference type so they are stored on heap
It cannot be inherited It can be inherited
Structure should be used when you want to use a small data structure Class is better choice for complex data structure
Structure elements cannot be declared as protected Class elements can be declared as protected
GC does not call finalize method for them because structure are not terminated GC does call finalize method for them because class are terminated
Structure does not require constructor Class does require constructor
The member variable of structure cannot be initialized directly The member variable of class can be initialized directly
It can only have parameterized constructor It can have all types of constructor and destructor

 

Categorized in: