This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 36478
    
  16
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: 36478
    
  16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Placement/Position of Constructor Does not Matter ?
 
Similar Threads
Block execution
Inheritance again
How initializer blocks help to share a block of code between multiple constructors?
initialization sequence
Could you change the static value declaration?(scjp07-95))