wood burning stoves 2.0*
The moose likes Java in General and the fly likes Placement/Position of Constructor Does not Matter ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Placement/Position of Constructor Does not Matter ?" Watch "Placement/Position of Constructor Does not Matter ?" New topic
Author

Placement/Position of Constructor Does not Matter ?

Karan Kaw
Greenhorn

Joined: Jan 05, 2013
Posts: 11


Value after intializer field : 1
Value after instance block : 5
Value in client after constructor : 10



I was so busy following good code conventions, That I never realized That Constructors could be placed anywhere; even after the fields that they initialize.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
This shows the hazards of mixing constructors and initialisers. Also you said initialiser field, which is misleading you. Have a look in the Java Language Specification about the order in which constructors, initialisers, etc are executed in instantiation. It might be this section.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
Karan Kaw wrote: . . . I was so busy following good code conventions . . .
That is a meaning of the word “good” which I am not familiar with
 
Don't get me started about those stupid light bulbs.
 
subject: Placement/Position of Constructor Does not Matter ?