This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why i cant tell it to his Father?  RSS feed

 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Plase take a look on this short code:

those are the compiling errors:
"TellFather.java": Error #: 310 : cannot reference variable up before superclass constructor has been called at line 12, column 37
"TellFather.java": Error #: 310 : cannot reference variable buttom before superclass constructor has been called at line 12, column 40

Can you explain why I cant do this in this way? If I can please show me how.
Thanks
Shay Gaghe
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shay,
You can't do it that way because the Super class all Superclasses will be completed before you are initialized. What does that mean? It means that your instance variables are not available (initialized) until the SuperClass has been completely constructed. Since you are explicitly calling the super class you can't send in your instance variables because they don't exist yet! You can however, divide the chore into multiple steps. Instead of sending in up and buttom buttons into the super constructor call just set them up after the first line. For example, the code below will work.

Regards,
Manfred.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!