File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how java allocates space for objects methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how java allocates space for objects methods " Watch "how java allocates space for objects methods " New topic
Author

how java allocates space for objects methods

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
Hi I don't know whether this question is right?


Say I have a class Animal and have created three objects of that class type.


I want to know whether all objects a,b,c share same method in jvm memory space or each object have their own copy of method1


Anil Deshpande
SCJP 1.5, SCWCD 1.5
Ramasamy Anbalagan
Greenhorn

Joined: Dec 14, 2009
Posts: 20
Hi Anil,

Each object having their own copy of Method1 string value.
Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30
Dear,
All the objects will share same copy........
If you make any change in the method,
It will affect on all the objects...
So, changing in one method affecting all the objects means that all the objects share same copy....
Right...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
Why do you need to know that in the first place?

I know it is a bit out of date, but the BCEL handbook is a good starting-point for such questions.
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
My friend had recently attended a interview for a teaching faculty job.

This question was asked to him. He exactly said that all objects share the same copy of the method.Even I had agreed to him. The person who was doing the interview disagreed.

So I wanted to confirm the answer.

Thanks a lot for clarifying.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
So, what did your friend say when given incorrect information in an interview?
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
Don't know, have to ask him
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how java allocates space for objects methods