Tuesday 6 January 2015


Encapsulation: Binding the details(int,char,float,string) together in a class is called encapsulation.


  Class is also like a structure. Compared to structures, C++ class has the following extra features

Features of class in C++:

1) Protect

2) Private

3)Public



Above declared variables can be visible to everywhere in our program. 

Because, we have mentioned that the class variables are public.

Creating a class variable is called “object”.

Enhancing this object from class is called “enhancement”.


Here the scope of variables is within the class itself. Class data members will not be accessed by others except limited persons(authorized). Members/functions can only accessed by private persons only.


Here it will give syntax error. If we place public instead of private, it will execute successfully.



To access data  outside function, we need to use the following format in main function.



To access data inside function, we need to use the following format.



Write a program to set and display data



Write a program to set date


Program to find sum of two numbers



We can declare a function within a class or outside a class.
Example program to write function outside class.



Here both get() functions are not same. One is related to class. Another one is general function.
All functions which are defined in class are to be considered as inline.


Syntax:



We need to add inline if the function definition is outside the class.



Example: program to find height of two persons( passing objects as arguments)



Read More