Saturday, July 28, 2012

Difference between Class and Structure


1)    structure :- In structure have a by default public.
In class have a by default private.
2)    Structure cannot be inherited. But class can be
inherit.
3)    There is no data hiding features comes with
structures. Classes do, private, protected and public.
4)    A structure can't be abstract, a class can.
5)    A structure is a value type, while a class is a
reference type.
6)    A structure is contain only data member , but class
contain data member and member function.
7)    In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
8)    Structure are value type, They are stored as a
stack on memory. where as class are reference type. They
are stored as heap on memory.


note: 'this' pointer will work only in class.

No comments:

Post a Comment