This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Use of static in abstract class.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

Use of static in abstract class..

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
What exactly is the use of static methods in abstract classes. They can never be overloaded. Are there any classes in java api where a class is abstract and all its methods are static

Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
I suppose that if you had a class with "service" methods but you didn't want anyone to instantiate it you could create an abstract class that had nothing but static methods. That way other classes could call the methods but not instantiate it.
I don't know of any classes that use this mechanism, but there are other ways of accomplishing the same goal. If you look at the "java.lang.Math" class, it has a bunch of convenience methods that perform mathematical operations. The class itself is declared as "final". All of the methods are "static". And it has a single constructor that's declared as "private". Therefore it can't be instantiated, and it can't be extended.
But either methodology works. It's a matter of conceptually deciding how the class is to be used.
[ October 10, 2003: Message edited by: Wayne L Johnson ]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Continue the conversation here.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Use of static in abstract class..
It's not a secret anymore!