Bloomberg LP Interview Question for Financial Software Developers






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

Brooks is right. As written, the code segment will compile. However, the function definition:
void Base::method() { n = 1;}
is ignored because the function method() in the base class is a pure virtual function. If one attempts to instantiate an object of either of the types Base or D1, the program will fail. The error will state that an abstract class cannot be instantiated.

- Wandering programmer February 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Fails at

A(int ii , int jj) :i(ii),j(ii){}

. Pure virtual function can not be defined. To make it work, a class should be derived from Base class and then it can be over ridden.

- cirus February 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It works. Virtual function is the function which can be overload by it's decendent.

- Anonymous February 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It could be compiled but the base class's definition of pure virtual func is not necessary.

- Brooks February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As far my understanding goes, it wont compile.
Once the method is defined to be pure virtual in base class, it IS pure virtual function. all derived classes should implement it.

(Wierd enough, compiler wont complain abt definition of the function even after its declaration to be pure virtual.

- Anonymous March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should compile. If a base class has a pure virtual function, an implementation for that function can be provided in any of the descendants of that class.Since, D1 does not provide a definition of the virtual function "method1", D1 is abstract too and cannot be instantiated.

- Rob March 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pure virtual function can be defined(but not inside the class). It can be accessed using the scope resolution operator from derived object as well.
If the derived class is not over riding the pure virtual function then derived class will become abstract (like the base).

The code will compile

- Karthik March 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess it won't since the class D1 is inherits Base class as private " class D1 : Base {}; "
so the method () will no longer will be accessible by the class D2 as well as D1 too.

- raja roy August 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It compiles. No problem with the code

- Richa Aggarwal November 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The inplementation of pure virtual function will be ignored by the compiler, unless it is pure virtual destructor.



class Basez 
{
public :
	virtual void method () = 0;
private :
	int n;
};

void Basez::method() 
{ n = 1;} // will be ignored in compilation time

class D1z : Basez {};

class D2z : public D1z
{
	int i;
	void method() {i = 2;}
};



"main":

//Basez bsz; // cannot do this
Derivez* dsz = new D2z();
dsz->method();
//dsz->Basez::method(); // cannot do this

- sergey.a.kabanov January 14, 2012 | Flag


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