aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructors" Watch "Constructors" New topic
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: 3883
    
  18

I don't see many spelling mistakes, just one small typo. Please carry on with the subject, guys.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
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: 3883
    
  18

You can't use both super() and this() in a constructor, only one of the two.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructors
 
It's not a secret anymore!