File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods belong to class" Watch "Methods belong to class" New topic

Methods belong to class

Niranjan Prasad
Ranch Hand

Joined: Aug 13, 2005
Posts: 62
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.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

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 8 API documentation
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:
subject: Methods belong to class
It's not a secret anymore!