Class in C++, What is Class, What is Object, How to use Class and Object,


 Class in C++

C++ is an object oriented programming language so it use class to binding data members and member function (function that use in the class) in a single program.

Class in C++


{tocify} $title={Table of Contents}
Definition of class:-

                               Class is a user define data type and it binding the data and function in single unit and give more security by access specifires that can be public private and protected

(We discuss in next blog)

When you define a class, you define a blueprint for a data type. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.

To define a class we using the Class keywords to define the class after that we give class name that can give by you (because class in a user define data type) to start programming in this class we use open and close curly braces “{}” in this curly braces we define access specifier to secure the data by third person after that we declare the member function. In the end of the close braces we use semicolon to end the class.

#include <iostream.h>
#include <conio.h>
Class simple           //Class keyword and class name
{                                 
Public:                          // access specifier
Int x;                           
Void display()             //Class function
        {
              Cin >>”enter the value of x”>>x;
             Cout<<”value of x is”<<x;
         }
};                               
Void main()            //main function
{
simple  s1;                  //creating an object (s1)
s1.display()                 //call a class function by object
}
After the end of class we create main function to create an object to call the member function and data member of class.


Data science & data analyst

C++

Algorithms

Technology


Post a Comment

Ask any query by comments

Previous Post Next Post