• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Q5+Q6 Dan

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Dmitry Golynkin
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, my JBuilder types the same. But why did it type compiler error? What is the border between copmiler and runtime errors?
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
https://coderanch.com/t/239025/java-programmer-SCJP/certification/runtime-vs-compiler-error
 
reply
    Bookmark Topic Watch Topic
  • New Topic