File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 39877
    
  28
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: 39877
    
  28
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
 
 
subject: Placement/Position of Constructor Does not Matter ?