• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Placement/Position of Constructor Does not Matter ?

 
Karan Kaw
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic