Classes in C++:-: Syntax For Class Declaration:-Example
Classes in C++:-: Syntax For Class Declaration:-Example
Classes in C++:-
A Class is used to pack data members and member functions together.
The Class has mechanism to prevent direct access to its members which is central idea of
Object Oriented Programming.
The Class declaration is also known as formation of new abstract data type. The abstract
data type can be used to as basic data type such as int,float..etc.
The “Class” is a keyword. The class declaration is same as struct declaration. The
declaration of class is enclosed with curly braces ( { }) and terminated with semicolon (;).
The data members and member functions can be declared in two sections. That is private
and public.
The Private and Public keywords are terminated with a colon ( : ).
The object cannot directly access the data members and member functions declared in
Private section. But it can access the data members and member functions declared in
Public section.
The Private Members of a class can only be accessed by Public member functions of the
same class. It is also possible to access private member variables directly like public
member variables provided that the class should have at least one public member
variable.
Both the private and public member variables are stored in consecutive memory locations
in the memory.
A pointer to member variable provides address of member variable. By applying
increment (++) and decrement (--) operations on pointer, we can access all private and
public member variables of the class.
The object of a class contains address of the first member variable. It can also be used to
access the private or public data.
Syntax:-
<class name> <object name>