CPP
Virtual
Function & Polymorphism
Fill in the blanks
1.Polymorphism means Multitask
2.Types of
Polymorphism Compile Time , Runtime
3.Compile Time
Polymorphism is Function name Same, Argument different
4.RunTime Polymorphism
is Function name Same, Argument Same
5.Compile Time
polymorphism types 2(Function overloading,Operator overloading)
6.Runtime Polymorphism
is Virtual function
7.Virtual function
keyword virtual
8.Virtual function
cannot be static member.[T/F]. True
9.Abstract class
could not be used for creating objects.
10.Pure virtual
function syntax [ = 0 ]
Answer the following Question
(4 marks)
1.Write a Program for Virtual function Polymorphism
#include<iostream.h>
#include<conio.h>
class
base{
public:
virtual
void show()
{
cout<<"base
class";
}
};
class
derived : public base
{
public:
void
show()
{
cout<<"Derived";
}
};
void
main()
{
base
*p;
p=new
base();
p->show();
p=new
derived();
p->show();
getch();
}
No comments:
Post a Comment