*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes does every object have its own method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "does every object have its own method" Watch "does every object have its own method" New topic
Author

does every object have its own method

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi All

Kindly clarify this
Say i have a class with 3 non static methods
Now when i create 10 objects of this class
i think
each object would have its own set (copies) of the methods
Correct me if i am wrong.
This was the question asked in 1 of the interviews & they told me
that each object will have only copies of non static members
(variables) & not of non static methods

Rgrds
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Yes manish, you are correct... non-static member are not shared betwen object, however static members are.
Check the following code


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Xara Mithra
Greenhorn

Joined: Nov 17, 2003
Posts: 12
Just Ran this program. Output as follows
t1.x=100
t2.x=100
t1.y=10
t2.y=0
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by manish ahuja:
i think each object would have its own set (copies) of the methods
Why would you need multiple copies of the methods?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi Thomas
I dont need multiple copies of amethod
what i wanted to know was whether each object would be having its own copy of non static methods
In case of static methods, there would be only 1
Jus wanted to know what is the behaviour in JAVA
Rgrds
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

There will be no multiple copies of method whether the method is static or non-static.


Groovy
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by manish ahuja:
I dont need multiple copies of amethod
Then why do you think Java would create multiple copies of a method?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: does every object have its own method
 
Similar Threads
difference between static synchronized method and non static synchronized method
Two threads calling the same method
about inner class
Serialization is not for static variables - Really true?
Class locks & non-static methods