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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 38075
    
  22
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: 38075
    
  22
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Placement/Position of Constructor Does not Matter ?
 
Similar Threads
Could you change the static value declaration?(scjp07-95))
How initializer blocks help to share a block of code between multiple constructors?
initialization sequence
Inheritance again
Block execution