Page 78 - Modular_V2.0_C++_Flikpbook
P. 78
For example, a dog has some properties like colour, breed, hairs, ear, etc. and behaviour like
barking, eating, sleeping, etc.
Object
(dog)
Properties Behaviour
(colour, breed, hairs) (barking, eating, sleeping)
Similarly, in object-oriented programming an object has attributes (properties) and behaviour
(functions to manipulate these attributes).
Class
A class can be defined as a user defined blueprint or prototype 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 ClassName
{
public: // Public data members and member functions
private: // Private data members and member functions
};
Where, A class is defined using the class keyword followed by a valid name (ClassName). The
class body is enclosed within curly braces { }. It contains access specifiers such as public: and
private:. Members declared under public: can be accessed from outside the class, while those under
private: can only be accessed within the class. The class consists of attributes (data members)
and methods (functions). The definition must end with a semicolon (;). Let's create a program to
understand the concept better.
76
Touchpad MODULAR (Ver. 2.0)

