C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 32)
32.
Which of the following concepts is used to implement late binding?
Virtual function
Operator function
Const function
Static function
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
7 comments Page 1 of 1.

Hemanth kumar said:   1 decade ago
#include <iostream>
using namespace std;

struct A {
virtual void f() { cout << "Class A" << endl; }
};

struct B: A {
void f() { cout << "Class B" << endl; }
};

void g(A& arg) {
arg.f();
}

int main() {
B x;
g(x);
}

Lingesh said:   1 decade ago
Virtual function is declaring method in base class and redefining method in subclasses. So when we call a method, both classes contain same method but it will call the subclass method only.

Anitha said:   10 years ago
During compilation when the compiler encounters the keyword "virtual", then it postpones binding to some extent, which is called as late or dynamic binding.

Priyanka p said:   1 decade ago
Late binding means dynamic binding and dynamic binding happen through the virtual keyword of function.

Shivank gupta said:   5 years ago
Great answer, thanks @Anitha.
(2)

Bholaram said:   9 years ago
Good explanation @Priyanka.

John said:   1 decade ago
What is virtual function?

Post your comments here:

Your comments will be displayed after verification.