File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructors example" Watch "constructors example" New topic
Author

constructors example

Swapna Ayyalaraju
Greenhorn

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
swapna
[ 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="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" 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
    Hi,

    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: http://aspose.com/file-tools
     
    subject: constructors example