Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Methods

 
Samer Memon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wht is the difference in static and non static methods in terms of memory.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samer Memon:
wht is the difference in static and non static methods in terms of memory.
Nothing whatsoever. It's state (i.e. instance variables), not methods, that takes a certain amount of memory per object.
- Peter

 
Samer Memon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks peter. my question is still the same. ok not methods ,is there any difference in static and instance variables in terms of memory.
Thanks in advance
Samer
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samer,
Well, only one static variable will exist per class. With non-static variables you'll get one for every object created. The more objects you create, the more memory you use.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
murali kante
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
think in terms of Design time (compile time ) and run time. The memory is allocated at run time for non static variables.
Same with methods aswell. If u declare a method1()( in class A) as static and want to use this method in another class B, you dont need to create new Instance of A, u can directly say A.method1().
Hope this helps
Murali
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic