+ 2

Classes and objects ?

Can anyone give me a simple explanation on objects and classes because i'm a little bit stuck in here.

20th Nov 2019, 4:06 PM
DAKIR ALLAH Abderrahman
DAKIR ALLAH Abderrahman - avatar
6 Answers
+ 4
Consider Humans as a class. They have different identity, behaviour and characteristics isn't it? So for example let us say they have a name, age, height, weight etc. Then they can also eat, sleep, walk etc. So now if you observe clearly you can see that almost all of us belong to the human class. So a class is nothing but a blueprint for an object. It contains the required details about the object. By now you should have guessed that we are all objects of Human class. Now take this simple example. class Human{ private: string name; int age; double height; double weight; public: void eat() { } void sleep() { } void walk() { } }; // Object creation Human obj1, obj2, obj3; Hope you get it now👍
20th Nov 2019, 5:06 PM
Avinesh - avatar
+ 3
Avinesh thanks bro it's clear now
20th Nov 2019, 6:18 PM
DAKIR ALLAH Abderrahman
DAKIR ALLAH Abderrahman - avatar
+ 1
Thank you so much
23rd Nov 2019, 5:13 PM
Digvijay Singh
Digvijay Singh - avatar
+ 1
Sagar Gupta Human is a class or you can call it a user defined data type. And obj1 obj2 are all objects. This is in C++.
6th Apr 2020, 10:43 PM
Avinesh - avatar
+ 1
Thanks Avinesh
8th Nov 2020, 11:05 AM
Manan Gandecha
Manan Gandecha - avatar
Avinesh so here human in human obj1 is class or object? And what about reference variable?
6th Apr 2020, 10:32 PM
Sagar Gupta
Sagar Gupta - avatar