• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

methods are loaded before instance live

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Methods are loaded into memory before any instance created, so if you created a static method then this method will just be like any instance method, but the JVM will give you access to it before any instantiation of the object.

therefore the static methods have no effect on memory, its effect on memory just like the effect of access modifier.

Verify this please
Thanks
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well it still has _some_ effect on memory, the method and it's stack of instructions still need to be loaded in the JVM.

Heh, Campbell beat me to it with a much better explanation, I'd stick to his
[ November 03, 2008: Message edited by: Martijn Verburg ]
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't load methods, but the class. Each method lives in the class, as you can see from descriptions of classes (eg the BCEL manual). Each instance method has an additional argument for the location of the object it is called on.
So all the methods are loaded inside the class; instance methods are not accessible until there is an instance to call them on. So all methods are put into memory as soon as the class is mentioned, even if you can't call them until there is an instance.

Static methods, however, are accessible from the name of the class as soon as the class file is loaded, which means as soon as the class name is mentioned in your code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic