+ 2
Classes and objects ?
Can anyone give me a simple explanation on objects and classes because i'm a little bit stuck in here.
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đ
+ 3
Avinesh thanks bro it's clear now
+ 1
Thank you so much
+ 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++.
+ 1
Thanks Avinesh
0
Avinesh so here human in human obj1 is class or object? And what about reference variable?