wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes instance methods - separate copies? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instance methods - separate copies?" Watch "instance methods - separate copies?" New topic
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: 18529
    
  40

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: 18529
    
  40

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance methods - separate copies?
 
Similar Threads
basic OO
Object Accessibility
Method sharing
Confusion in threads
Regarding running multiple instances of an application