| Author |
instance methods - separate copies?
|
Iris Rawleigh
Greenhorn
Joined: Feb 15, 2009
Posts: 2
|
|
Clearly every instance of a class has its own copy of an instance variable. But when it comes to methods, does every instance actually have a separate copy of the code of a non-static method?
Thanks
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Iris Rawleigh wrote:Clearly every instance of a class has its own copy of an instance variable. But when it comes to methods, does every instance actually have a separate copy of the code of a non-static method?
Thanks
No. The main difference between an instance method and a static method is that an instance method gets a reference to the object that calls it (the "this" instance). The actual location of the methods are not stored with the instances.
Henry
|
 |
Iris Rawleigh
Greenhorn
Joined: Feb 15, 2009
Posts: 2
|
|
Henry Wong wrote:
No. The main difference between an instance method and a static method is that an instance method gets a reference to the object that calls it (the "this" instance). The actual location of the methods are not stored with the instances.
Henry
Ah, ok that makes more sense. Are these references stored on the stack?
Iris
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Iris Rawleigh wrote:
Ah, ok that makes more sense. Are these references stored on the stack?
Iris
EDIT >>>> Sorry, mis-read you question.... Yes, the "this" reference is one of the parameters to the method, so yes, it is pushed onto the stack during the call.
Henry
|
 |
 |
|
|
subject: instance methods - separate copies?
|
|
|