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

Khalid pg 333-334

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When does Java create a symbol table of the class variables being used? The variable occupancyPerRoom is not declared until (3), then how does the method initMaxGuests() know that is even exists?
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cathy
I have summarize the list of things that happen when an object of a class is created. It has been derived from the same book that you have referred. I would request others to correct me if I'm wrong as I'm no expert in Java. Here's my list (note that the order of steps is important):
1. Static variable initializer expressions and static initializer blocks are executed in the order they are specified.
2. All the instance variables are initialized to their default values (eg. integers are initialized to 0, strings to null, etc etc)
3. The appropriate class constructor is invoked. This can lead to the local chaining of constructors. The constructor at the end of the chain invokes the super class constructor (implicitly or explicitly). (Constructor chaining ensures that the inherited state of the object is constructed first).
4. Initialization of the instance member variables by executing their instance initializer expressions and any instance initializer blocks in the order they are specified.
5. Execution of constructor body.
Therefore, if we apply the above list of actions to your example:
- At step 2, occupancyPerRoom is initialized to 0.
- At step 4, the expression maxNoOfGuests = initMaxGuests () is executed, which prints the value of occupancyPerRoom as 0.
I'm not sure if I answered your question correctly but I tried
Thanks
Harwinder
[ October 19, 2003: Message edited by: Harwinder Bhatia ]
 
You can't expect to wield supreme executive power just because
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic