Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implementation for static and non-static methods stored in memory

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this program i have created two objects s1 and s2 of class sample. The display function(which is member function of
class sample) has common implementation which is shared by s1 and s2. Where is the implementation for the dispaly function
stored? Where is the implementation for static and non-static methods stored in memory?

class sample
{
void display()
{
System.out.println("hello");
}
}

class MainClass
{
public static void main(String str[])
{
sample s1 = new sample();
sample s2 = new sample();
s1.display();
s2.display();
}
}
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methods are stored in the stack. Objects and instance variables are in the heap.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic