This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Methods belong to class

 
Niranjan Prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic