Difference between class and object

Object oriented programming interview questions and answers c# vb.net asp.net

Many programmers still get confused by the difference between class and object. In object-oriented terminology, a Class is a template for Objects and every Object must belong to a Class. The terms "Class" and "Object" are related to one another and each term holds its own distinct meaning.

A class is a construct that defines a collection of properties and methods in a single unit, which does not change during the execution of a program. Objects are created and eventually destroyed during the execution of a program, so they only live in the program for a short time. While objects are "living" their attributes may also be changed at execution of a program.

Every object belongs to a class and every class contains one or more related objects. That means, a Class is created once and Object is created from the same Class many time as they require. There is no memory space allocation for a Class when it is crated, while memory space is allocated for an Object when it is created.

Difference between class and object c# vb.net asp.net

Here is an example that will help you to clarify the above points. Suppose we have a class called "CAR". All CAR have bodies, engines etc. and these could be the attributes (properties) of our CAR class. We can also add some methods (functions) that would be common to all CAR like movement (forward and reverse), because all CAR can move . So, the idea you really want to enforce in your own mind is that the 'template' of a CAR does not change. Each Object was built from the same set of template (Class) and therefore contains the same components. All Objects share the same copy of the member functions (methods), but maintain a separate copy of the member data (Properties). For example: A Ford car and a Toyota car are both Cars, so they can be classified as belonging to the Car class. All have same movement (methods) but different in models (properties).