Dover Organization Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

Virtual function: This is a technique for polymorphism in OOP. To understand it simply, suppose Class A is a Base class and Class B is Derived from A. and some func() is defined in both these classes i.e. function overriding. Now, we have a pointer to base class A and we want to ensure that right function is to be called based on the type of object this base class pointer is holding. so we simply declare func() in base as virtual func(). So whenever func() will be called with pointer holding derived class object, firstly func() of derived class will be called, but in case it is not defined in derived then ultimately base func() will get called.
is it helpful?

Pure virtual function: is often used for creating interfaces/abstract_classes. these functions may not have a body and it's mandatory to override it in derived classes..

- ptrip.jnu May 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Virtual Function is a very important aspect of inheritance in any object-oriented language.
Suppose you have a base class A and child class B.
{class A{
protected virtual void func();
}
class B : public A
{
void func()
{
some code;
}
}
A *a;
B b =new B();
a = &b;
a->func();
}
As you can see from this code, depending on the what object, the pointer 'a' points to, at run time it is decided that method func() in class B has to be called. This is called virtual function.

Now, when will it be useful?. Consider a big application source code which has a base class and several child classes inheriting from it. Just think about how much redundant code has to be written if we don't use virtual functions.

- Vyas April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

www[DOT]parashift[DOT]com/c++-faq-lite/virtual-functions[DOT]html

- vips April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

refer eckel

- Arya June 23, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More