It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructors example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructors example" Watch "constructors example" New topic

constructors example

Swapna Ayyalaraju

Joined: Apr 24, 2008
Posts: 1
hi all......
can some one explain me this rule with example

"only static variables and methods can be accessed as part of call to super() or this()"

thanks and regards
[ April 24, 2008: Message edited by: Swapna Ayyalaraju ]
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
where did you find that rule???
you mean super()

<a href="" target="_blank" rel="nofollow">Use Real Words</a> <a href="" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Dumitru Postoronca
Ranch Hand

Joined: May 06, 2008
Posts: 46
Thats because the order of initialization is this:
  • Init static members
  • Call super constructor
  • Init instance members

  • So at the point where you call super(...) your instance variables are not initialized yet so you can't use them.
    Ivan Ivanic
    Ranch Hand

    Joined: Oct 31, 2007
    Posts: 100

    Mustafa Musaji
    Ranch Hand

    Joined: May 03, 2008
    Posts: 52

    You are confusing this.methodName() with a this() contructor call. Or the same goes for super(). I'm not very good at explaining so hopefully the below example will help.

    SCJP 5.0 - Passed
    I agree. Here's the link:
    subject: constructors example
    jQuery in Action, 3rd edition