Question: 18. Using the concept of pure virtual function write a program with following specifiction a) Create two classes A and B b) Class A has
18. Using the concept of pure virtual function write a program with following specifiction a) Create two classes A and B b) Class A has public access modifier and function called show which is pure virtual and displays "Base Class" c) class B inherits class A also has public access modifier and function show which is virtual and displays "Derived class" d) Create pointer object of class A and simple object of class B. Class A pointer object will point to class B 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. Virtual Keyword is used to make a member function of the base class Virtual
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
