| Author |
Constructors
|
Hama Kamal
Ranch Hand
Joined: May 29, 2011
Posts: 144
|
|
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.
|
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
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?
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3050
|
|
|
I don't see many spelling mistakes, just one small typo. Please carry on with the subject, guys.
|
 |
Hama Kamal
Ranch Hand
Joined: May 29, 2011
Posts: 144
|
|
|
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
Joined: Sep 20, 2010
Posts: 3050
|
|
|
You can't use both super() and this() in a constructor, only one of the two.
|
 |
 |
|
|
subject: Constructors
|
|
|