Page 70 - Modular_V1.1_Flipbook
P. 70
Object
(dog)
Properties Behaviour
(colour, breed, hairs) (barking, eating, sleeping)
Similarly, in object-oriented programming an object has attributes (properties) and behaviour
(methods to manipulate attributes).
Class
A class can be defined as a user defined blueprint or prototype that is used to create objects.
It contains objects that have similar properties and behaviour. For example, an animal class has
different types of animals.
Animal
Cat Tiger Dog
All the animals in the animal class have similar behaviour such as eating, drinking and sleeping.
They also have similar properties such as colour, size and number of legs. In the same way, a
class in C++ contains different types of objects that have similar properties and behaviour. After
declaring a class, we can create a number of objects from it.
In C++, the class keyword is used to create a class. Following is the syntax to create a class:
class <class-name> {
public/private: // Access specifier
<data members declaration section> // Attribute declaration section
};
Where, <class-name> is any valid identifier to assign a name to a class. The body of the
class is started with the opening curly brace and closed with the closing brace at the end. The
public/private is any one of the two access specifiers to specify the accessibility level of the data
members of the class. The specifier should be followed by colon (:) symbol. The public members
of the class can be accessed outside the class. Whereas the private members of the class can be
accessed only inside the class in which they are declared. After the closing curly brace, semicolon
is used to terminate the class definition. Let us create a program to understand the concept better.
Program 1: To create and use a class.
#include<iostream.h>
#include<conio.h>
class Car {
68 Touchpad MODULAR (Version 1.1)-X

