wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q5+Q6 Dan Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q5+Q6 Dan" Watch "Q5+Q6 Dan" New topic
Author

Q5+Q6 Dan

Dmitry Golynkin
Greenhorn

Joined: Aug 13, 2002
Posts: 23

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 ]

good luck
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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 8.8.5.1 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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Dmitry Golynkin
Greenhorn

Joined: Aug 13, 2002
Posts: 23
Yes, my JBuilder types the same. But why did it type compiler error? What is the border between copmiler and runtime errors?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
But why did it type compiler error? What is the border between copmiler and runtime errors?
Please see the following recent discussion about the same topic:
http://www.coderanch.com/t/239025/java-programmer-SCJP/certification/runtime-vs-compiler-error
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q5+Q6 Dan