Monday, 26 April 2021

Virtual Function in C++ Qus - 1

 class A

{

public:

   

 virtual void show()

  {

    

      cout<<"Hello"<<endl;

  }

  

};


class B: public A

{

    public:

   

   void show()

  {

    

      cout<<"India"<<endl;

  }

    

 

};

int main() {

    B *b=new B;

    b->show();

    A *b1=new B;

     b1->show();

 

}



Output:


India

Hello

2 comments: