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 Methods belong to class 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 » Java » Beginning Java
Bookmark "Methods belong to class" Watch "Methods belong to class" New topic
Author

Methods belong to class

Niranjan Prasad
Ranch Hand

Joined: Aug 13, 2005
Posts: 62
Hi
This is Niranjan

When Object is created only instance variable get memory allocation and so
can we say that only instance variables belong to Object and all the methods(instance and static methods) belong to Class.

Niranjan
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Yes, you could say that. For each object (= instance of a class) space is allocated for the instance variables; for static variables, there's only 1 set of them that is shared between all the instances of a class.

Methods consist of executable byte code, and there's always only one copy of the byte code necessary, whether the method is static or not.
[ October 26, 2005: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Even before there were objects some operating systems separated code and data this way. They only need to load one copy of the code no matter how many users or threads are executing it, but each user or thread needs its own copy of the data to work on. It's pretty cool when you get into how it works.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods belong to class
 
Similar Threads
static variables, methods
why can't static class fields be serialized?
Overriding static methods
Static Methods and Instance Methods
tricky/confusing questions