This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance initializers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "instance initializers" Watch "instance initializers" New topic
Author

instance initializers

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 622
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: 622
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: 8712
how about some sample code?


Eliminate fossil fuel subsidies. (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: 622
Thanks Guys.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: instance initializers
 
Similar Threads
code in curly braces of class can be run?why?
Initialization
non-static block
Help.explanation of code from different classes
Java Free Blocks