• Post Reply Bookmark Topic Watch Topic
  • New Topic

private static methods.  RSS feed

 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.

Can anyone explain me how this can be done?
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhishek Reddy Chepyala:
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable...

I don't think I understand this premise.

Can you show us where this came from?
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek -

The advantage of static methods is that they're independent of any particular class instance.

The opposite of a "static" method is an "instance" method. In Java, the default is "instance method": whenever you invoke that method, it is with respect to one - and only one - object instance.

You can have static methods ... or static member data.

I'm not sure how any of this relates to your original question:
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.
<= HUH?!?


Frankly, I'd have to say that, although there might be a kernel of truth lurking in there someplace ... the above statement is basically nonsense.

IMHO .. PSM
[ September 23, 2006: Message edited by: Paul Santa Maria ]
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable.

The above words are from "java.sun.com" tutorials under "Static Initialization Blocks" section here is the link http://java.sun.com/docs/books/tutorial/java/javaOO/initial.html
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.

You can call a static method whenever you want, but a static initialization block is called only when the class is loaded. Therefore, static methods are somewhat more flexible. If a class has static data which may need to be re-initialized at some point, then it makes more sense to put that initialization code in a static method (perhaps calling it from a static initialization block!) so that the method can be called again at some other time.

You would have got your answer sooner if you had explained your question more.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see the missing piece now...

The advantage of private static methods [over static initialization blocks] is that they can be reused later if you need to reinitialize the class variable.
 
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Its cool and straight forward.

1) The static init. block will be called only once, that to at the time of class loading.

2) Static methods can be called when every you want.

3) Private Static ( you can call when ever you want from your class local methods and can initialize only static data).

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!