Bloomberg LP Interview Question for Financial Software Developers






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

final class in java : does not allow a class to be subclassed.

c++ , we can make use of private keyword and make all data in a class private ie. constructor , methods and data needs to be declared in private section. There is no keyword that we can use on class to prevent it from subclassing.

final keyword for variable : in c++ make it const , i guess.

final methods : In c++ , we cannot avoid subclasses overloading or overriding it.
let me know if i m wrong.

- sonu February 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please refer to the most recent posting about the same question.

- drwolf February 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is funny. I see that one of the replies got a -1! If I recall correctly, this question was posted around 5-6 times (currently it seems to appear two times). I would have expected positive votes for that response.

Strange forum.

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

Declare that class in unnamed namespace.

- jindal.vikash April 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i agree with desi and i must say what drwolf is also correct meaning thereby,
#. if yuo just make the constructor private then its enough for any deriving class to not make any subclass on that, and we don't need to do other things as mentioned by drwolf, but that doesnot say his answer is wrong, drwolf add extra steps to do the same, which can be avoided.
# yeh, the reference has to be declared as const else there is no point ...

@ Monkey
if you are not interested in discussing the questions plz do not make bogus posts regarding thread duplication...just do a "report duplicate thread" right from the homepage and you're done...
and don't waste your time by keeping track of duplicate threads, i guess you're not here to do that, right? or its the other way round? OMG...!!!

- desiDaaro August 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wouldn't a static factory method defeat the private constructor?

- Tim December 12, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Final Class: (which can not be sub-classed further)
---------------------------------------------------
if you just make the constructor private, we can achieve 'final' effect, but no other code can create objects of the class. This is not intended. So, making constructor private alone will not achieve the goal. So, we need to so something else.

Final Method: (Which can not be over-written)
---------------------------------------------
In Java all the methods by default are virtual. So, the real question here is, in C++ how can we make a virtual function not being re-implemented again in sub-class. In C++ if a method is declared as virtual, it will be virtual in all the hierarchy of classes. How to stop this at some class in the hierarchy? In Java, it is achieved by the 'final' keyword and javac compiler check.

Final Data Member: (Whose value can not be changed)
----------------------------------------------------
This can be achieved by 'const' as desi mentioned.


Anyone who knows the exact answer for "final class" and "final method" implementation in c++??????????????

- WinWin January 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use virtual inheritance and friend class to solve this.

class FinalLock
{
private:
FinalLock(){};
~FinalLock(){};
friend Final;
};

class Final : public virtual FinalLock
{
};

class D : public Final
{
};

Final fObj; // OK

D dObj // error!! since FinalLock constructor is private

- venkat September 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Is virtual inheritance is required?

- creation December 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

venkat, your idea is correct, but your program is not. The reason is stated in the above compilation error.
The constructor should not be private, but the destructor can be private.

class A {
private:
//	A() {};
	~A() {};
	friend class Final;

};

class FinalA : public virtual A
{
};

class FinalB : public virtual A
{

};

int main() {
	FinalA fa;
	//FinalB fb;  //Error in Compile
	return 0;
}

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

1. Final keyword in Java means, we can not derive any class from final class but we can certainly create object of Final class.

2. We can implement Final in C++ like below. It allows you to create object of Final class but it does not allow you to derive new class.


class Final; // The class to be made final

class MakeFinal // used to make the Final class final
{
private:
MakeFinal() { cout << "MakFinal constructor" << endl; }
friend class Final;
};

class Final : virtual MakeFinal
{
public:
Final() { cout << "Final constructor" << endl; }
};

/*class Derived : public Final // Compiler error
{
public:
Derived() { cout << "Derived constructor" << endl; }
};
*/
int main(int argc, char **argv)
{
Final obj;

}

- keyurpatel80 May 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 0 vote

Is this the final time this question will be asked?

- Anonymous February 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

:D :D :)

- divyaC May 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
-1
of 0 vote

(1) final class: we cannot inherit from it, that is, not allowable for making subclass. ---> In c++, we make a same effect by declaring the class to private class. Even if we can inherit with private inheritance, there is no meaning because subclass cannot use or access any memeber in that class.
(2) final method: cannot overload it. In c++, we can declare the method as private. Similarily, the subclass cannot access the method.
(3) final variable: one time initialization constant variable. In c++, we can define a reference variable for the same effect as one time initialization and never updated its initial value.

- drwolf February 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I dont agree with drwolf on the

point 1), you should just make the constructor as private and that will prevent the derivation of the class.

and 3) we need to use the keyword "const" to make sure that the contents of the reference do not change, because const doesnt allow the programmer/application to change the value.

- desi February 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If you make the constructor private then how will create an instance of the class?

- Anonymous January 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

#include <stdio.h>

class foo
{
foo();
};

int main()
{
foo f;
return 0;
}

output:
test-final-class.cpp: In function ‘int main()’:
test-final-class.cpp:5: error: ‘foo::foo()’ is private
test-final-class.cpp:10: error: within this context

- Anonymous January 03, 2010 | 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