+ 9
what is the different b/w clases and objects?
i had tried to understand both of them please tel me some answer
18 ответов
+ 18
Think like this.
Class is data type (user defined)
Object is variable of type 'class'
As you must have seen in cpp course class is templates, blueprint for object.
Take an example:
You make a class of 'fruit'.
class fruit{
private:
string name;
string taste;
bool has_seeds;
float market_price;
};
Once you define a class you can declare objects of that type (class)
Like....
fruit mango; //mango is fruit now
Now mango is an object of type (class) fruit..
Similar to..
int number; //here we used to declare number as interger.
classes allowed programmers to create their own datatypes and organize data in much efficient way by introducing several oop concepts .
BTW, how did you complete your course without knowing this 🤔
+ 11
An object is an instance of a class.
+ 8
Class is the idea (an imagination) of something, it is imaginary, you can't use a class directly because it is unreal. We need to create something real to work with, based on that idea. This real thing we call object - an instance of a class (a real thing created based on the imagination/idea of it). An object is something we can work with, because it is real.
The process of creating a real thing (object) from the imagination (class) is called instantiation. We can create (instantiate) multiple instances from a class, just like we can bake many cakes, while all the cakes are baked on the same cake pan and ingredients, that would mean all the cakes will have similar form and flavour (an oversimplified example).
Hth, cmiiw
+ 7
Class is like a blue print.
This blue print contains tools (methods, variables, codes etc) to create and manipulate an object.
So a class can also be called a container.
An object is a real thing created. So its an instance of a class.
an object can be created from a class.
you can create multiple objects from a single class.
P.S: guess we all saying same thing here lol. 🙃🙃
+ 6
A class is like a group, and objects are like the members of the group
+ 6
Class is a collection of similar objects . Class is just a data type (user defined) and an object is a variable of that data type. Class is just a blueprint for creating objects.
+ 6
class is a blueprint and object is the product
+ 5
Object is a instance of a class. Which is more likely a copy of the data structure of the class.
+ 2
objects are instances of classes just like variables of complier defined datatypes
+ 2
A ”class” is like the descriptive blueprint of a house.
An ”object” is an instance of a class. It is like the actual house itself created using the blueprint.
There can only be a single class or blueprint definition. There can be several instances of the class or blueprint. For example, there can be several houses created out of the same design or blueprint.
+ 1
Any specific language?
+ 1
A class is a human.
Human can talk, human can walk...
Human has a name, human has two human parents...
An object is you, a particular instance of a human. With your name, your parents. And you talk like humans and walk like humans do.
+ 1
I m giving u a real life example to understand it better. Every thing u see around u is an object while class is the blue print of that object.
Example:
If u want to build a house, the first thing u will do is to make a map of the house that is the class. Using that map u can build any number of houses. These houses are the objects of that class.
👍
0
Class is Like schema for house, but object is when you build a house of that schema. You can build many houses with the same schema. Like objects from class.
0
Sounds like bigbang and creation of universe
0
Objects are instances of classes.to make it clear I'll give you a paradigm assume there is a shirt, There can be different types of shirts based on characteristics so you define a class shirt using different characteristics,then u instantiate objects having different values of characteristics.
Eg: class shirt{
char colour[10];
int size;
public:
getdetail(){.......};
putdetail(){....};
}shirt1,shirt2;
Now in above example shirt one and two are objects of a class but one can differ from two in characteristics given.and both belongs to class shirt
- 1
حاتم علي عوض الجيزاني رقم