Difference between class and object
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.
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).
- What is object-oriented programming?
- What is a Class?
- What is an Object?
- Constructors and Destructors
- What Is Inheritance ?
- What are the different types of inheritance ?
- What are Access Modifiers ?
- Why Classes cannot be declared as Protected?
- Can we declare private class in namespace
- Difference between Classes and Structures
- Can we use pointers in C# ?
- Why abstract class can't create instance
- Can you prevent your class from being inherited
- Difference between method Overloading and Overriding
- Difference between Early Binding and Late binding
- What is nested class
- What is partial class ?
- What is Virtual Method
- What is Data Encapsulation?
- Object Based Language and OOPs
- SOLID Principles in Object-Oriented Programming
- Solid Principles | Advantages and Disadvantages