Classes and Objects in OOPS
In this article, you will know about Classes are the most important constituents of Object Oriented Programming (OOPS). What is OOPS and its definition?.
Learn about Classes constituents of Object Oriented Programming
Classes are the most important constituents of Object Oriented Programming.
A class is just a template which contains the various attributes and functions of an object of the class.
For example,
Consider a class bird.
A bird class will have the following attributes:
1. Color
2. Height
3. Weight
4. Habitat
5. nature
It will also have the following functions
1. Flight
2. Sound
etc.,
A class gives you only the attributes.
If you ask 10 different persons to think of a bird and describe, each one will describe it differently. Because it is just a general name.
An object is a run-time entity of a class.
Say, you create an object parrot from the class bird. Then you know the value for all the parameters for this particular object. If you create another object duck, then this object will also have all the parameters defined for the class bird. But, the values for the parameters would be different from that of the object parrot.
Another example :
consider
int a;
here, I can think of 'a' as an object of the class 'int'.
>>Class is a logical representation of data with related methods
>>Object is a physical representation of data based on class and it is called as instance of class
eg.Human being is class whereas any person is an object