my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance initializers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instance initializers" Watch "instance initializers" New topic
Author

instance initializers

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Hi all,

Are instance initializers the labeled loops we write? Or are they something else?

Thanks.


Be Humble... Be Nice.
vidhya suvarna
Ranch Hand

Joined: Aug 28, 2008
Posts: 148
They are instance variables that belong to a class and get initialized before the constructed is called.


SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
After the constructor is called right?
vidhya suvarna
Ranch Hand

Joined: Aug 28, 2008
Posts: 148
No, before the constructor is called.

Suppose the subclass constructor is called which invokes the superclass constructor then, 1st superclass variables are intialized and the constructor is run. Then controls come to subclass constructor where again 1st subclass variables are intialized and then the constructor run.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
how about some sample code?


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
Am I correct if I say that in the following code, "initvar" is an instance initializer?

The output of this code is:

In Super's constructor. initvar value = 100
Done calling super() in Sub class


[ September 28, 2008: Message edited by: Rekha Srinath ]
vidhya suvarna
Ranch Hand

Joined: Aug 28, 2008
Posts: 148
Yes Rekha, thats correct.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Thanks Guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance initializers