Difference between class and object in oops

Difference between class and object in oops


Class is collection of related data elements (member variables and member functions)that bind together and act as a single unit.In real world example animals, fruits, vegetables,solar system is class.

Once non static class has been defined we can create any no. of objects belonging to that class.Objects are runtime entity that represents  particular class.From above example of class tiger,dog,cat,lion etc are objects of class animals similarly earth, Saturn, Mars etc are objects of solar system.Objects may communicate with each other through functions.


(Eg:- consider there's two objects student and marks,We are preparing marksheet for each student ,Both objects can communicate with each other through functions to prepare marksheet.)

But remember data of an object cannot be directly accessed ,only those functions that are bind within objects can access it.

Class is the fields and variable's created but its not a real entity's these fields are not accessible until and unless they are not in shape of real entity it's mean that the class is just a blueprint or imagination of an object and the object is a real entity

A class defines a type.  An object is an instance of a type.  A class without an instance of that class is pretty much useless.  Think of it as a class defines something where a object is an actual instance/allocated memory for a given class.

Post a Comment

Post a Comment (0)

Previous Post Next Post