File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructors example

 
Swapna Ayyalaraju
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where did you find that rule???
you mean super()
 
Dumitru Postoronca
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 100
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

     
    Mustafa Musaji
    Ranch Hand
    Posts: 52
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic