#include < iostream.h >
#include < conio.h >
class base{
int i;
public:
void set_i(int num){i=num;}
int get_i(){return i;}
};
class derived:public base{
  int j;
  public:
  void set_j(int num) {j=num;}
  int get_j(){return j;}
  };
  void main()
  {
  base *bp;
  derived d;
  clrscr();
  bp=&d;
  bp->set_i(77);
  cout << "\n\n Using the member of base class: " << bp->get_i();
  //cout << "\n\n Using the member of derived class: " << bp->get_j(); is wrong
 //bp->set_j(55); this is also wrong as using pointer of base class you
 // can not access the members of derived class
 getch();
 }
Click here to go back.

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus


Footer1