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

again constructor

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to understand, what is all about the instance variable's default value prints before super constructor has completed.Can anyone please explain it with code or give me a link if any?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dolly,
The way I think of it is the JVM allocates such storage from the heap (as opposed to the stack). This is true for instance variables and static data. At the time of allocation it clears the data to zeros (which explains the default values for all variable types).

Only later (either at class loading for static initialisers), or constructors for (class instances) does the JVM run any initial assigement code (but before the constructor chain runs up the class heirarchy.

Finally, your class constructor code itself runs (as the JVM executes back down the class hierarchy) when /that/ code may start to over-write JVM defaults / static assignments.

(ok, there may be steps I've missed - it's late and I've drunk some wine ;-)
It all seemed logical to me when I studied the detail - though I can't help thinking in 'C' terms for some of this - NO "POINTERS" MY AR^H^H^H^H^H^H^H^H^H I'm an OO programmer, honest ;-)
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic