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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Use of static in abstract class..

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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 ]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Continue the conversation here.
 
Crusading Chameleon likes the size of this ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    Bookmark Topic Watch Topic
  • New Topic