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

Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

4248


How to call a non virtual function in the derived class by using base class pointer

5285


• What are the desirable attributes for memory managment?

1732


What are two types of polymorphism?

616


What is object in oop?

691






How do you explain polymorphism?

598


What is inheritance and how many types of inheritance?

624


What is encapsulation in oops?

541


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

1645


There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.

1463


How do you achieve polymorphism?

619


What are the benefits of oop?

609


write knight tour problem which is present in datastructure

2170


Is oop better than procedural?

580


What is inheritance in simple words?

629