I was testing my luck on the Java SE 7 Programmer I - Sample Questions and the very first question has me scratching my head. The print out is x,y,c,g. Why does y print before c? Thank You
Line 4 is the body of the constructor of class Sequence.
Line 5 is an instance initializer block.
Instance initializer blocks execute before the constructor executes, that's why you see "y" before "c".
The code has been formatted in a way that is delibrately misleading - it looks like a trick question.
Line 16 is a static initializer block, which executes when class Sequence is loaded and initialized (even before the main() method executes) - that's why you see "x" first.
Jesper de Jong wrote:Line 4 is the body of the constructor of class Sequence.
Line 5 is an instance initializer block.
Instance initializer blocks execute before the constructor executes, that's why you see "y" before "c".
The code has been formatted in a way that is delibrately misleading - it looks like a trick question.
Line 16 is a static initializer block, which executes when class Sequence is loaded and initialized (even before the main() method executes) - that's why you see "x" first.
Thank you very much!
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking