Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Creation of Object Q

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following code works fine. Question is how value of av is available before completion of constructor? (I think, class members - methods and variables (except static) are available only after completion of constructor). Please correct if i am wrong.

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Nitin Bhagwat:
I think, class members - methods and variables (except static) are available only after completion of constructor



Instance members are actually initialized prior to the constructor being executed so all instance members are available within the constructor.
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nitin,
The concept is this. Consider a base class and derived class has static initialiser block and instance initialiser block. The order of execution is as follows :
===
STATIC Instance Initialiser - Base
STATIC Instance Initialiser - Derived
Instance Initialiser - Base
Parent cons. called
Instance Initialiser - Derived
Constructor of derived
===
Below is a code. Try that and you will get it.


Cheers!
_Mani
 
Nitin Bhagwat
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mani, Excellent help!
 
What are you doing? You are supposed to be reading this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic