User Menu

Login



Share with

OOP PDF Print E-mail

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 –

class Kangra

{

  private:
  int m;  // m is only accessible within the class 

  protected:
  int n // n is only accessible within the class and

       // to the subclass of Kangra
 public:

 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 –

class Kangra

{

        public:

        Kangra()

            {       }

        int area(int a)

         {

          return a*a;

         }

       int area( int a,int b);   //Overloaded function

         {

          return a*b;

         }  

};

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.

For example-

class A

{

         Public :

         int a ,b;

         void show ()

          {

          cout<<a<<b;

          }

};
class B: private A //Use of Inheritance

{

       int c;

       void dispdata ()

        {

         cout<<c;

        }

};

scroll back to top