What is Virtual Keyword?

Answer Posted / danish afzal

Virtual is important part of polymorphism,and if a function of a base class is virtual we can use or override it in drived classes.

class base
{
virtual void foo() const
{
cout << "danish B";
}
};
class derived1 :public base
{
void foo() const
{
cout << "danish D1";
}

};
class derived2 :public base
{
void foo() const
{
cout << "danish D2";
}

};

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does and I oop mean in text?

620


What is an example of genetic polymorphism?

647


What is the real time example of encapsulation?

595


What is the difference between procedural programming and oops?

552


What is coupling in oop?

597






Plese get me a perfect C++ program for railway/airway reservation with all details.

3427


Why do we use inheritance?

628


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1147


What does and I oop and sksksk mean?

650


Why is abstraction needed?

567


What is oops concept with example?

576


when to use 'mutable' keyword and when to use 'const cast' in c++

1642


Why is destructor used?

581


What is overloading in oops?

596


what is graphics

2011