x

C++ Objects and Classes

PREV     NEXT

C++ Objects and Classes:


What is class in C++?

  • As C++ is a multi-paradigm programming language so, it supports different programming styles and it supports object oriented programming which helps us to divide the complex problems into smaller sets by creating objects.
  • So, to understand the objects you should know about the class. A class is a blueprint for the object. It is a user defined data type which holds the data members and member functions of its own and can be accessed and used by creating the instance of the class.
  • It does not define any data but I does define what the class name is and what the object of that class will consist, what operations can be performed on that object.
  • The class definition starts with the keyword class followed by the class name and the class body that is enclosed by a pair of curly braces {}.
  • The class definition must be followed either by a semicolon or a list of declarations.

What is an object?

The class provides the blueprint for the objects so; objects are created from within the class. The objects of a class are declared exactly with the same sort of declaration that we declare the variables of basic types.


How to access the data members?

The data members can be defined as public, private and protected but defining as public they can be accessed using the direct member access operator (.).

To understand the concept clearly let us have a look at the example:

PREV     NEXT



Like it? Please Spread the word!