Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Memory Space Allocation and subclasses
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Marc Twain, post: 552438"] This is a bit of a tricky question... but I'm sure the gurus among you will know the answer :) From the reference I learned that when an object is created, the following occurs: 1- The memory space is allocate and initialized to default 2- Explicit initialization is performed 3- A constructor is called. So far, so good. Now what happens when dealing with subclasses? I would assume that step 1, 2 are executed for the current class, then step 3 kicks in. Now because this is a subclass, the parent constructor is called as the first line in the constructor block, either implicitly or explicitly (if the 'no arg' constructor in the parent class is absent). Then the parent class would go through steps 1, 2 and 3 again. Sounds good? Well the reference states something different. It says that step 1, 2, 3 occur for the subclass, then after the call to the parent constructor ONLY step 2 and 3 kick in for the parent class. Which does not make any sense, since step 2 (Explicit init of the member variables) cannot take place without step one (Memory space allocation?). So what it is? Does Java magically traverse the class hierarchy in Step one, looking for any possible parent variables? Or is this just a typo? TIA, AJ [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Memory Space Allocation and subclasses
Top