What is the difference between Class and structure?

Author Topic: What is the difference between Class and structure?  (Read 818 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • Hot Shaper
     Structure used to bundle data’s of different data types to perform a particular function. Extended function of the structure is the class.
The major difference is that any variable declared inside the structure is public whereas any variable declared inside the class is private, meaning the variable has meaning only inside the class.


Offline michral86

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 17
  • Karma: 0
  • Gender: Female
Re: What is the difference between Class and structure?
« Reply #1 on: 04-25-2017, 03:16:16 »
You can differentiate  Class and Structure as below:
Class
Class is a reference type and its object is created on the heap memory. It can inherit the another class. It can have the all types of constructor and destructor.
Example:
obj=new Demo();
Structure
Structure is a value type that is why its object is created on the stack memory.
It does not support the inheritance. It can only have the parametrized constructor. it means a structure can not have the non-parametrized constructor,default constructor and destructor also.
Example:
Demo obj;
I hope my answer helps you.

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
764 Views
Last post 07-20-2012, 01:09:31
by tomjohn
0 Replies
537 Views
Last post 02-13-2016, 00:36:44
by chinmay.sahoo
3 Replies
1725 Views
Last post 12-13-2016, 23:31:12
by saravjeet
0 Replies
615 Views
Last post 09-03-2016, 03:43:26
by beingchinmay
1 Replies
664 Views
Last post 01-18-2017, 00:26:30
by wellliving