This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
avi sinha wrote:
static blocks -- > super constructor --- > init() blocks ---> constructor
static blocks --> init of a ---> constructor of a ---> init of b ---> constructor of b ---> init of c ---> constructor of c
I think you should keep static blocks out of this. They are executed only the first time a class is loaded and not with each instance. The sequence is superclass constructor, then initialization expressions and instance initializer blocks in the order of their declaration, then the constructor body. This is not very difficult to understand so there should be no confusion.
As far as the original question goes, you can say that the question has a bug, and for C to be the right answer, there must be inheritance relationship between Small, Small2 and Small3...
Are you saying that scjptest.com is showing that C) 'a b c'; is the correct answer? .
If that is the case, then you should email the creators and let them know.
There is nothing wrong with this code, just like everyone on this thread is saying.
I also complied and executed the program and B) not C) is the correct answer
Joined: Aug 23, 2007
You all realize this thread was more than a month old? Anyway, the test that this comes from at scjptest.com is pretty
buggy. Like many of the tests listed in the FAQ, it has a very good interface but the questions need editing. It
*could* be a great resource i they'd debug it and edit some of the wrong questions.
Joined: Feb 28, 2008
Most definitely the ans is wrong.. it is B) c .. i missed it, thanks Ankit, i need to be more alert.. the classes are missing inheritance. Now when I say "other super constructors", I mean this:
The sequence of the output is numbered. Hope this make it clearer.