+ 3

What is a difference between class and struct?

5th Jun 2016, 12:39 PM
Aso Harutyunyan
Aso Harutyunyan - avatar
8 Réponses
+ 6
structs are used to represent a bundle of data(only properties), classes are modelling a complete object with properties and behaviour.
11th Jun 2016, 7:27 AM
Dom Cabrinha
Dom Cabrinha - avatar
+ 5
Primarily, it's the status/visibility of their members. Class members are private by default, while struct members are public by default.
11th Jun 2016, 6:52 AM
Bryce Bexell
Bryce Bexell - avatar
+ 4
Classes are reference types while structs are value types.
11th Jun 2016, 1:50 AM
Jafca
Jafca - avatar
+ 3
struct doesn't allow you to treat it like built in data type but Classes behaves like built in data type. secondly, you can not hide the data from outside world in struct. But you can do it with classes. Third, you can not perform normal binary operation like C=A+B with struct. But you can do it with Classes using overloading. Last, struct doesn't allow us to inherit another struct. And as you know you can do with class.
12th Jun 2016, 4:23 PM
Vishal Koshti
Vishal Koshti - avatar
+ 3
you can have public,private data in class. it is private by default whereas,in struct you can have only public data. in struct it is public by default.. also cannot inherit from another struct in struct...whereas it is possible in class.
14th Jun 2016, 12:02 PM
NITESH SHINDE
NITESH SHINDE - avatar
+ 2
classes are collection of data(variables) and methods. structs are collection of data (variables).
11th Jun 2016, 10:41 PM
ahmed osama
ahmed osama - avatar
+ 2
class is somewhat like structure. But it has both data members and functions whereas sturucture doesn't have member function.
13th Jun 2016, 8:14 AM
Anol Maria Jacob
Anol Maria Jacob - avatar
0
One is reference type another one is value type!
16th Jun 2016, 8:50 PM
Utpal Kumar
Utpal Kumar - avatar