| Author |
instance initializer
|
Deep Chand
Ranch Hand
Joined: Dec 17, 2002
Posts: 133
|
|
Hi all, This may sound really dumb :-) but I'm confused about 'instance initializer'. I know that static initializer exists for the whole class i.e. run when the class is loaded. Constructor is executed when the instance is created. Then what's this 'instance initializer'? any comments would be sincerely appreciated. cheers, Deep
|
 |
Dhanashree Mankar
Ranch Hand
Joined: Aug 25, 2003
Posts: 123
|
|
Originally posted by Deep Chand: Hi all, This may sound really dumb :-) but I'm confused about 'instance initializer'. I know that static initializer exists for the whole class i.e. run when the class is loaded. Constructor is executed when the instance is created. Then what's this 'instance initializer'? any comments would be sincerely appreciated. cheers, Deep
___________________________________________________________________________ instance initializer is made to use in annonymous classes. since annonymous classes are not having constructers ,instance initializers are used to initialize variables in annonymous classes.
|
 |
Deep Chand
Ranch Hand
Joined: Dec 17, 2002
Posts: 133
|
|
Does that mean they are only present in the anonymous classes and not anywhere else? Correct? Thanks, Deep
|
 |
Alton Hernandez
Ranch Hand
Joined: May 30, 2003
Posts: 443
|
|
Hi, Instance initializer is like static initializer except that the codes within that block are invoked everytime an instance is created. One of its use is to group codes that are common to all the constructor of the class. Example: Instead of: You can change it to: You can also use it in anonymous class to initialize something in the instance. Hope this helps. [ August 26, 2003: Message edited by: Alton Hernandez ]
|
 |
Deep Chand
Ranch Hand
Joined: Dec 17, 2002
Posts: 133
|
|
|
Thanks.
|
 |
 |
|
|
subject: instance initializer
|
|
|