Question: 17 . Using the concept of runtime polymorphism write a program with following specification a) Create two classes base and derived b) Class base has
17 . Using the concept of runtime polymorphism write a program with following specification a) Create two classes base and derived b) Class base has public access modifier and function called show which is virtual and displays "Base Class" c) Derived class also has public access modifier and function show which displays "Derived class" d) Create pointer object of base class and simple object of derived class base class pointer object will point to derived class object finally display show function of derived class. Description: In C++ Run time polymorphism can be achieve by using virtual function. Virtual Function is a function in base class, which is override in the derived class, and which tells the compiler to perform Late Binding on this function. In Late Binding function call is resolved at runtime. Hence, now compiler determines the type of object at runtime, and then binds the function call. Late Binding is also called Dynamic Binding or Runtime Binding. This is also sometimes called early binding because the area() function is set during the compilation of the program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
