Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Object Initialization

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is a cookbook for object initialization, with final variable initialization considerations included. Tell me what you think.
Object initialization involves constructing the initial state of the object when it�s created using the "new" operator. These are the steps taken:
1. Instance variables are initialized to their default values.
2. Local constructor is invoked. This can lead to local constructor chaining.
3. Superclass�s constructor is invoked, either implicitly or explicitly from the end of the local constructor chain. The superclass�s constructor then executes to completion. Thus, the inherited state of the object is constructed first.
4. Instance member variables are then initialized by executing their instance initializer expressions.
5. If any instance initializer blocks are coded, they�re executed in the order they�re specified in the class definition. If a final var is initialized in step 4, it can�t be changed in step 5.
6. If a final var is initialized in steps 4 or 5, it can�t be changed by a local constructor.
7. If a local constructor chain exists, constructor execution resumes with the local constructor at the end of the chain. Constructor execution then procedes down the local contructor chain, in reverse invocation order.
8. The local constructor that was originally invoked is executed.
9. If a final var isn�t initialized by now, it�s a compiler error.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is right!!.
 
it's a teeny, tiny, wafer thin ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic