a. Polymorphism is one of the main object-oriented concepts in programming. It describes one form and many implementations. A real-world object or function can be represented in many forms. Even though the functionality is the same, the way the functionality performed might be different.
-> It helps the programmers on program code reusability.
-> It provides an ability to implement the same operations in a different way.
-> It reduces coupling between the functionalities.
Don't use plagiarized sources. Get Your Custom Essay on
Question: Polymorphism Question 8 (a) What is polymorphism in object oriented programming? Is it really nee……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
There are 2 types of polymorphism. They are compiled time and run-time polymorphism. Compile time polymorphism is implemented using function overloading whereas dynamic polymorphism implemented using function overriding.
Consider a real time example: In an organization, there is a need for employee performance evaluation. The performance evaluation depends on the type of employee. Based on the type, the evaluation criteria also differ. So, the functionality performanceEvaluation is same but differs in the way it is implemented.
b. A virtual keyword determines runtime polymorphism. A keyword virtual before member function of the base class can be over-ridden by the derived class. We do not use a virtual keyword for every method in C++.
When we don’t know what functionality exactly to be implemented in the base class. In such case, a class can be made abstract which can be implemented by its derived class. In order to make the class abstract, the virtual function should present. The pure virtual function doesn’t have an implementation but it has the only declaration in the base class.
virtual void evaluate() = 0;
c. Object slicing is when a derived class object is being assigned to the base class. It causes additional attributes of an object from the derived class are sliced off to form the base class object.
Base base = derived; // Object Slicing
In order to prevent this behavior, by making base class function as pure virtual function thereby it disallows object creation. It is known that it is not possible to create the object of a class which contains a pure virtual function.