Overview On Class And Structure

What is class

Class is used to create our own data type using predefined data types like int, float, string, etc.

Class contains data members (say : int num) & data functions (say: public static hello();).

What is structure

Structure is used to create our own data type using predefined data types like int, float, string etc.

Structure contains only data members (say : int number) and no data functions.



Example- Here I have given a real life example

Suppose I want to prepare Veg fried rice so there is a book called structure in that they have given ingredients, but no procedure to make veg fried rice. In the same way structure contains data members but no method logic.

Suppose I want to prepare Veg friend rice so there is a book called class in that they have given ingredients and also procedure to make veg friend rice. In the same way class contains data members and method logic.


Next Recommended Reading Difference Between Class And Structure