In this article we will see what are all the differnece between a class and structure.
Structure
|
Class
|
Value
type
|
Reference
type
|
After
instantiation memory will be created on stack.
|
After
instantiation memory will be created on heap
|
Does
not Support inheritance. But can implement interfaces
|
Supports
inheritance and implementation of interfaces
|
Does
not support default( parameter less )constructor
|
It
supports default(parameter less) constructor
|
Cannot
define destructor
|
Can
have destructor
|
Does
not permit initialization of instance fields with in definition
|
Permits
initialization of instance fields with in definition
|
On
assignment values data is copied
|
On
assignment copies the reference
|
Memory
deallocation done when they go out of scope
|
Memory
deallocation handled by garbage collector.
|
0 Comments:
Post a Comment