Prasanna Lakkur Subramanyam wrote:1. Firstly, is my understanding so far correct?
Prasanna Lakkur Subramanyam wrote:2. Second, I understand that instance variables get initialized to 0(or their default value) when they're first encountered(before their super classes are initialized). Is the same true for static variables as well?
Prasanna Lakkur Subramanyam wrote:3. When are methods available for use? In every book that I've read, they always mention when variables should or should not be used but they never talk about methods. Are all the methods of an object available and ready to be called as soon as the object creation has started?
Trying to collect the broken pieces of my life,in the process of making out a beautiful picture out of it.
I hadn't been here for fifteen years
Prasanna Lakkur Subramanyam wrote:1. Firstly, is my understanding so far correct? (please look at the image)
2. Second, I understand that instance variables get initialized to 0(or their default value) when they're first encountered(before their super classes are initialized). Is the same true for static variables as well?
3. When are methods available for use? In every book that I've read, they always mention when variables should or should not be used but they never talk about methods. Are all the methods of an object available and ready to be called as soon as the object creation has started?
A.J. Côté wrote:As a rule of thumb, always refer to static fileds and methods by prefixing them with the class name, e.g. MyClass.getX(), MySubclass.getX(). This should make everything clearer.
Prasanna Lakkur Subramanyam wrote:
I was thinking about this for some time now. And I've come up with a sort of an understand of how it might work.
-> The Class object for the particular class is loaded before anything else.
Prasanna Lakkur Subramanyam wrote:
-> There is only one copy of the methods in the memory and every object just passes the this reference to the method.
So, if the methods actually exist in the Class object(and this is where I'm not too clear about things), then the methods will obviously be available before execution of any code in that particular class.
Prasanna Lakkur Subramanyam wrote:I did not specify what the circles meant. The circles are the objects. There are only three object in total. The three circles on the left represent the objects during the static initialization phase. The ones on the right, during the instance initialization phase.
Prasanna Lakkur Subramanyam wrote:-> The Class object for the particular class is loaded before anything else.
Prasanna Lakkur Subramanyam wrote:-> There is only one copy of the methods in the memory and every object just passes the this reference to the method.
So, if the methods actually exist in the Class object(and this is where I'm not too clear about things), then the methods will obviously be available before execution of any code in that particular class.
Prasanna Lakkur Subramanyam wrote:@Roel De Nijs: ha-ha yes! One object and two super classes(and no, they're not direct super classes). Got me there.
Beware the other head of science - it bites! Nibble on this message:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|