Object Oriented Programming
A type of programming in which main concentration is on DATA rather than on ALGORITHM
Characteristics of Object Oriented Programming
Data encapsulation – Encapsulation is the process of combining data and methods into a single unit called class.
Using encapsulation, nobody can directly access the data. Data is only accessible through the methods existing inside the class.
Data hiding – Hiding the implementation details of a class from the user. To ensure this class groups its members into three sections:
Private, protected and public
In which private and protected are hidden from the outside world
For example –
int m; // m is only accessible within the class
int n // n is only accessible within the class and
// to the subclass of Kangra
int p; //p is accessible inside and outside the class
Kangra() // constructor
Polymorphism – It is the ability for a message or data to be processed in more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types and number of data items used in the operation. Polymorphism is implemented using function overloading.
For example –
int area(int a)
int area( int a,int b); //Overloaded function
Inheritance – Inheritance is the process by which objects of one class can acquire the properties of objects of other class.
Inheritance provides code re-usability, like, adding additional features to an existing class without modifying it. This is achieved by deriving new class from the existing one. The new class will have combined features of both the classes.
int a ,b;
void show ()
class B: private A //Use of Inheritance
void dispdata ()