• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructors

 
Hama Kamal
Ranch Hand
Posts: 144
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,,

in the SCJP6 book ,,,( by katy and bert ) >>>>page 133 >> rules for constructors:
i dont get the following two points could any one expalin it more with giving simple illustrating example for each!

1-Only static variables and methods can be accessed as part of the call to super()
or this(). (Example: super(Animal.NAME) is OK, because NAME is
declared as a static variable.)
2-You cannot make a call to an instance method, or access an instance variable,
until after the super constructor runs.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hama Kamal wrote:hi guys,,

in the SCJP6 book ,,,( by katy and bert ) >>>>page 133 >> rules for constructors:
i dont get the following two points could any one expalin it more with giving simple illustrating example for each!

1-Only static variables and methods can be accessed as part of the call to super()
or this(). (Example: super(Animal.NAME) is OK, because NAME is
declared as a static variable.)
2-You cannot make a call to an instance method, or access an instance variable,
until after the super constructor runs.


Please UseRealWords! Before creating an object, how can you access it's instance variables?
 
Stephan van Hulst
Bartender
Posts: 6311
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see many spelling mistakes, just one small typo. Please carry on with the subject, guys.
 
Hama Kamal
Ranch Hand
Posts: 144
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
many thanks however, i have one more question,, if it happens in a constructor to have call to both super and this ,, which one comes first?
 
Stephan van Hulst
Bartender
Posts: 6311
77
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use both super() and this() in a constructor, only one of the two.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic