198. Write a program to demonstrate virtual function?

#include<iostream.h> #include<conio.h> class parent { public:                 virtual void show(int a)                                 {                                 cout<<"Parent Class Show() With Value : "<<a<<endl;                                 } }; class child:public parent { public:                 void show(int b)                                 {                                 cout<<"Child Class Show() With Value : "<<b<<endl;                                 } }; void main() {                 clrscr();                 parent *p;                ... Continue Reading →

Advertisements

197. Write a program to override the member function?

#include<iostream.h> #include<conio.h> class parent { public:                 void show()                                 {                                 cout<<"Parent Class Show()"<<endl;                                 } }; class child:public parent { public:                 void show()                                 {                                 cout<<"Child Class Show()"<<endl;                                 } }; void main() {                 clrscr();                 child c;                 c.show();                 parent p;                 p.show();                 c.parent::show();                 getch(); }

196. Write a program to check the output as flow of execution of constructor and destructor?

#include<iostream.h> #include<conio.h> class super { public:                 super()                                 {                                 cout<<"Base Class Constructor Called"<<endl;                                 }                 ~super()                                 {                                 cout<<"Base Class Destructor Called"<<endl;                                 getch();                                 } }; class sub:public super { public:                 sub()                                 {                                 cout<<"Child Class Constructor Called"<<endl;                                 }                 ~sub()                                 {                                 cout<<"Child Class Destructor... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: