C++ Tutorial Home Page

C++ OOPs Concepts

Introduction
Class
Objects
Abstraction
Encapsulation
Polymorphism
Inheritance
Dynamic Binding
Message Passing

C++ OOPs Concepts 4

What is the relationship between a class and its objects?

A class represents a group of similar objects. For instance
(i). “Student” is a class and “amit” is an object.
(ii). “Car” is a class and “maruti 800” is an object.

An object is an instance of the class. In c++ , class makes a data type using which its objects can be defined.

 

Explain the object and classes with examples?

Every object has properties and exhibits/shows certain behavior. Let us try to illustrate this point by taking an example of a “dog”.

A dog has properties like name, height, color, and age. These properties are represented by variables. Now the object dog will have some actions/operations like barking, running, eating, etc. these actions/operations are represented by various methods(functions) in our programming.

In programming, various tasks are done by method only. So we can conclude that an object contains variables and methods.

A group of objects exhibiting the same behavior (properties + actions) will come under the same group called a class.

A class represents a group name given to several objects. For example, take the dogs: Moti, Tomy, Tony, Rocky, etc All these dogs exhibit the same behavior and hence belong to the same group called Dog. So the dog is a class name and it contains four objects.

In other words, we can define a class as a model/blueprint to create objects.

Similarly, the flower is a class and a rose, Lily, Jasmine, and Lotus are all objects of the class flower.

The class flower does not exist physically but its objects exist physically.