Hi,
What is the Difference between class and object?
Regards,
Hi,
What is the Difference between class and object?
Regards,
An object is an instance of a class.
Such that, if class is:
class MyClass {
public:
int x;
};
Than an object would be:
int main()
{
MyClass my_object;
}
A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change. The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed. An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.
Class is a template(type) or blue print its state how objects should be and behave. eg consider a construction plan which is a class with this description mentioned in a plan we can constructs 'n' number of buildings of same type.
these buildings are consider to be an objects come under same type of that plan. Object is defined as a software construct which binds data
and logic or methods(functions)together.
In short: Class is templet for an object.Object is an instance of a class.
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner.
A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.
Let us consider the class car. Cars have a body, wheels, an engine, seats, are used to transport people between locations, and require at least one person in the car for it to move by its own power. These are some of the attributes of the class - car - and all members that this class has ever or will ever have share these attributes.
The members of the class - car - are objects and the objects are individual and specific cars. Each individual car has a creation date (an example of an object having an attribute that is static), an owner, a registered address (examples of attributes that may or may not change), a current location, current occupants, current fuel level (examples of attributes that change quickly), and it may be covered by insurance (an example of an attribute that may or may not exist).
To use a more programming related example, the class window has edges, a title bar, maximize and minimize buttons, and an area to display the window contents. A specific window has a location on the screen, a size, a title, and may or may not have something in the content area.
So basically the difference between a class and an object is that a class is a general concept while objects are the specific and real instances that embody that concept. When creating an object oriented program we define the classes and the relationships between the classes. We then execute the program to create, update, and destroy the objects which are the specific realization of these classes.
Bookmarks