Friday 10 February 2012

Class and Objects

Welcome to all readers. I will like to thank all my readers for reading this article this is my first article and I have decided to write my first article on class and objects because I strongly feel that many people (students) don’t know what class and object is.


Theoretically we have studied that class is a collection of data members and member functions and it is wrapper which is used to contain the functions, properties, events etc. In general words class is a category which is used to categorize the certain things. In practical life we people are also categorised and if we see the things around us everything is divided into class (category) just like we human beings are categorised according to caste, gender, religion, nationality etc. All these categories help us to organize the things.

Similarly in programming world class is also like a category which is used to categorise the things and it makes our work very flexible by providing many important features like reusability, maintainability, polymorphism, hiding etc which corresponds to the real world things.

Again in layman language I want to tell that a class is nothing but a hypothetical thing which actually does not exist. We thought of having something which should have properties, functionality and many other things. Just like bird is a class but actually bird is nothing if practically we don’t see any bird practically. Example if I say that there is a class of bird called abc and this class of bird have ten eyes, forty five legs, five nose etc. Now you might be wandering that where is that bird actually present.

Practically if I say that I have heard about that bird but actually I have not seen that means I have no proof or example of such class so everyone will definitely feel that such bird does not exist. So it means class is nothing if its example (instance i.e object) does not exist.

So here comes object in picture which indicates a mirror image or example of class (I am not considering static class because I just want to explain the meaning of class and object). So object is an instance of a class and we can say that it is a real world entity because it is an object which actually exist not a class which is hypothetical thing.

Since I have written that object is a mirror image of a class so object has all features and properties of class and object can access that. The above line again I will explain in terms of general language. Now just thing of a class birds we know that birds can fly so it is a function of bird’s class. All object (like sparrow, crow etc) are mirror image of this class and can access all the features which belong to this class. That’s why an object can access everything which is there in a class (public data, internal data).

So in the last I want to tell that class is a kind of category and object is an example (mirror image of that class).