Classes and Objects in C++ (Class an important feature of object oriented programming)

129 Просмотры
Издатель
WHAT IS A CLASS?
Class is an important feature of Object-Oriented programming.
It is an extension of ‘Structure’ in C.
A class is a user defined data type, where we can bind different type of variables and functions together in a single unit.
The variables are called ‘data members’ and functions are called ‘member functions’.
The general format of a class declaration:
class class-name
{
private:
member declaration
public:
member declaration
};
The class declaration begins with the keyword ‘class’. The body of a class is enclosed within braces and terminated by a semicolon. It contains declaration of variables and functions. By default, class members are made private.
ACCESS MODIFIERS / VISIBILITY MODES
C++ provides 3 access modifiers for defining members of a class: Public, Private and Protected.
Generally data members are made private. Therefore, it can only be accessed by the member functions of the class.
Member functions of the class are made public, so that these members can be accessed using objects of the class.
Категория
Язык программирования C++
Комментариев нет.