What is the difference between Class and structure?

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

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • We Helpline
     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 1
  • Posts: 34
  • 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.

Offline traveloweb

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 7
  • Karma: 0
Re: What is the difference between Class and structure?
« Reply #2 on: 01-11-2018, 03:29:45 »
The major difference like class provides the flexibility of combining data and methods (functions ) and it provides the re-usability called inheritance. Struct should typically be used for grouping data. The technical difference comes down to subtle issues about default visibility of members. Here you can see some of the Difference between Class and Structure.

Class is pass-by-reference and Struct is pass-by-copy, it means that, Class is a reference type and its object is created on the heap memory where as structure is a value type and its object is created on the stack memory

Offline richardmsmith

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 229
  • Karma: 0
  • Gender: Male
    • Trucking App Solution
Re: What is the difference between Class and structure?
« Reply #3 on: 07-17-2018, 02:52:40 »
A structure is a value type so it is stored on the stack, but a class is a reference type and is stored on the heap. A structure doesn't support inheritance, and polymorphism, but a class supports both. By default, all the struct members are public but class members are by default private in nature.

 

Related Topics

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