--%>

Polymorphism and types of polymorphism

Q. What do you mean by polymorphism? Explain all types of polymorphism.

                                            OR

What is polymorphism? Give an example to illustrate that public member data of base class member becomes the private member of data to derived class and the base class member of the data cannot be accessed in the main function (C++ should be used).  

Ans.

 

Polymorphism: The term polymorphism is derived from the Greek meaning that is many forms. It allows a single name to be used for more than a related purpose which is technically different. Polymorphism allows the programmer to create high level reusable components that may be tailored to fit distinct applications by altering their low level parts. It is a feature of Object oriented programming language. It merely means one name, multiple forms. It is done by overloading. There are three type of overloading:

 

1.      Operator  overloading

 

2.      Function  overloading

3.      Virtual function overloading

The overloaded member functions are selected for invoking by matching arguments, both type and number. This information is known to the compiler at the compile time and compiler is able to select the appropriate function for the particular part call at compile time itself. This is knows as early binding or static linking or static binding. Also called as compile time polymorphism, early binding just means that an object is bound to its function call at compile time. Now let us consider a situation where the function name and prototype is same in both the base and derived classes.

Example

Class Arun

{

Int x;

Void show ()

};

Class Lokesh : public Arun

{

Int y;

Public :

Void show ()

};

Here function shows its overloaded condition. It would be nice if the appropriate member function could be selected while the programme is running, this is known as run time polymorphism.

Example

Class A {

Public :

Int X;

Private :

Int Y;

Public :

Void show () {

Cout << "it is base class";

}

 Class B public A

{

Private

Int X;

Public :

     Void show () {

Cout << "it is derived class";

}

};

Void main ();

A a;

B b;

b. show ();

a. show ();

}

   Related Questions in Programming Languages

  • Q : What are the applications of testing

    What are the applications of testing life cycle?

  • Q : Explain Structured programming

    Structured programming: It is a style of programming generally related with languages like FORTRAN, C, Pascal and so forth. Employing structured programming methods, a problem is frequently resolved employing a divide and conquer approach like stepwis

  • Q : Explain the meaning of semantic

    Explain the meaning of semantic connotations.

  • Q : Explain Branch instruction Branch

    Branch instruction: It stores a new instruction address into the program counter. The consequence of this is the next instruction to be fetched will not generally be the one instantly following the branch instruction. Therefore the normal chronologica

  • Q : Define Absolute filename Absolute

    Absolute filename: It is a filename whose full path is unambiguously provided starting from the top (that is, root) of a file system tree. For example: c:\Java\bin\javac.exe

  • Q : Advantage of wrapping database calls in

    What is the advantage of wrapping database calls in MTS transactions?

  • Q : Type promotion rule Q. Explain type

    Q. Explain type conversion rules for basic data types in java. Ans. Type promotion rule: Java automatically each bits or short operant to int when evaluating an expression. As usual as the automatic promotion

  • Q : Explain Primitive Type Abstractions

    Primitive Type Abstractions: An effective way to reduce the state space of a program is to replace the primitive types with the corresponding abstractions that encapsulate all the possible operations that are performed on these types.

    Q : What are good examples of element

    What are good examples of element attributes?

  • Q : What is Block Block : The statements

    Block: The statements and declarations are enclosed between a matching pair of curly brackets ({ and }). For example, a class body is a block, as it is a method body. The block surrounds a nested scope level.