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 : Use the Alice Program Use the Alice

    Use the Alice Program from the link below to complete and save the five projects . http://alice.org/ (should be Alice 2.2 or newer) Assignment 1

    Q : Uses of BYTE Write a program that shows

    Write a program that shows the uses of BYTE, WORD and DWORD?

  • Q : CORBA allows high performance

    'CORBA was designed to allow high performance distributed applications to be written’. Discuss. Definitely, ’CORBA was designed to allow high performance distributed applications to be written’ because it provides:

  • Q : Explain Object reference Object

    Object reference: It is a reference to an object. Languages other than Java employ terms like pointer or address or. It is significant to keep the difference clear between an object and its reference. The variable like argo

    Q : Define the term Class constant Define

    Define the term Class constant: A variable which is defined as both final and static.

  • Q : Explain Operator Explain Operator with

    Explain Operator with their types and examples?

  • Q : Define the term Peripheral devices

    Define the term Peripheral devices: It is the devices attached to a computer, like disk drives, printers, mice, and so forth.

  • Q : Describe Data type Data type : It is a

    Data type: It is a specifier to build memory block of some particular size and kind. C++ provides two kinds of data types: A) Fundamental type: That is not composed

  • Q : Explain Call-by-value Call-by-value:

    Call-by-value: The semantics of passing an argument to a method in which a copy of actual argument value is taken and positioned in a separate memory location, symbolized by the corresponding formal argument. As an outcome, assignment to the formal ar

  • Q : Self-created What is the difference

    What is the difference among a self-created certificate, Symbian Signed and a Symbian developer certificate?

©TutorsGlobe All rights reserved 2022-2023.