IQOD #10

Posts 1–2 of 2 · Page 1 of 1
IQOD #10
Remember these are potential/possible Job-Interview Questions, so no googling, running it in your compiler etc. Pretend like you're in a conference room with nothing but a white board....

If you don't know the answer, you can simply say so or try to write out what you think it is...

This one is a 3 parter:

A) What is a pure virtual Function?


B)Consider the following code:
Code:
#include <iostream>
using namespace std;

Class A
{
	public:
		A() { this->Foo(); }
		virtual void Foo() { cout << "A::Foo()" << endl; }
};

Class B : public A
{
	public:
		B() { this->Foo(); }
		virtual void Foo() { cout << "B::Foo()" << endl; }
};

int main(int, char**)
{
	B ObjectB;
	return 0;
}
C)What output would it generate if you make A::Foo() a pure virtual function?
A) A pure virtual function is only a virtual function prototype, but with = 0; behind it:
virtual void Foo() = 0;
an implementation of the pure virtual function is not provided in an abstract class.
it may be included as long as the definition is not be included at the point of declaration.
B) The output is
A::Foo()
B::Foo()
since B derives from A(so B initiates A inside itself)
C) The output will not change?

since C failed I shall change my C) to:
ERROR
Posts 1–2 of 2 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us