What are the object oriented programs in C++ ?

No comments
Object Oriented Programs Are :-

      1.   Polymorphism
      2.    Inheritance
      3.   Encapsulation
      4.   Data Abstraction


1    .     Polymorphism :- It allows a single name/operator  to be associated with different operations depending on the type of data passed to it. In C++ it is achieved by function overlapping, operator overlapping and dynamic binding.

Example :-  int sum (int a, int b) {return (a+b);}
                      float sum (float a, float b){ return (a+b);}

The observe two functions used to add two integers and two float. The function will be called depending on the arguments passed to it.

2   .     Inheritance :-   It allows the extension and reuse of existing code with out having to re- write the code. Inheritance involves the creation of new classes from an existing class. New classes are called derived class /new class/child class/ sub-class and existing class is called base class /old class/parent class/ super class. The derive class inherit the members of base class and also add its own.

Example:- class A
                              {
                                         Int x;
                                         Public:
                                          Void display()
                                                 {
                                                       Cout <<x;
                                                 }
                                    };

                              Class B : public A
                                                   {
                                                          Int y;
                                                           Public:
                                                            Void show()
                                                                    {
                                                                         C out <<y;
                                                                      }
                                                         };

3  .  Encapsulation :- It is amechanism that associates the code and the data. It manipulates into a single unit(class) and keeps then safe from external encapsulation is supported by a construct called class.

Example :- class student
                           {
                                       private:
                                       int role;
                                       char * name;
                                    public :
                                        void getdata ();
                                        void showdata ();
                           };

Data and methods are encapsulated in class.

4  .  Data Abstraction :-  Data abstraction is the ebility to create user define data type or modeling real world objects using built in data types and a set of operators.

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀