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.
I've seen no problem with Q5 - compiler could see that |this| stands on the second place. But in Q6 compiler doesn't know that |j| can't reached before R() construction. Why compiler error??? Thank you guys for previous answers! [ August 27, 2002: Message edited by: Dmitry Golynkin ] [ August 27, 2002: Message edited by: Dmitry Golynkin ]
In this() or super() explicit constructor invocation you are not allowed to pass instance members (like j for instance) because the supertype is initialized prior to the subtype, thus j is not yet initialized when the superclass constructor is invoked. From JLS 184.108.40.206 Explicit Constructor Invocations
An explicit constructor invocation statement in a constructor body may not refer to any instance variables or instance methods declared in this class or any superclass, or use this or super in any expression; otherwise, a compile-time error occurs.
If you have a computer at hand you could try to compile the code and see what the compiler is saying. In this case it is saying: cannot reference j before supertype constructor has been called super(j);
The error message is very expressive, isn't it? Please format your code using CODE tags. [ August 27, 2002: Message edited by: Valentin Crettaz ]