aspose file tools
The moose likes Java in General and the fly likes Is a standalone abstract class of any use ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Is a standalone abstract class of any use ?" Watch "Is a standalone abstract class of any use ?" New topic
Author

Is a standalone abstract class of any use ?

Jayati Das
Greenhorn

Joined: Feb 01, 2007
Posts: 18
I was asked this in an interview recently , If an abstract class is not going to be extended ,does declaring a class abstract serve any purpose ?
I couldnt think of any use of a standalone abstract class.




SCJP5 85%
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
I suppose you could still call static methods on such a class, but I'd hardly call that a reason for having an abstract class that isn't extended. Sounds like one of those nice 'trivia' 'gotcha' questions some interviewers like.
Jayati Das
Greenhorn

Joined: Feb 01, 2007
Posts: 18
Thank you for replying.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4750
    
    7

Jayati Das wrote:If an abstract class is not going to be extended ,does declaring a class abstract serve any purpose?

I think my answer would be 'no', because the whole point of an abstract class is to be extended, so the idea of a 'standalone' abstract class is a bit of an oxymoron.

The only example that I can think of would be a constants-only interface, and those have generally been discredited.

However, I totally agree with Ralph: I think it's one of those 'gotcha' questions; and not very well worded at that.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3793
    
    1

I suspect they're thinking of a Utility - i.e. a class that only has static methods. For example, java.lang.Math.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
Utility classes are not usualloy abstract. They are usually unintantiable.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3793
    
    1

Campbell Ritchie wrote:Utility classes are not usualloy abstract. They are usually unintantiable.

I know. I still reckon that's probably what they were getting at, though .

Or, having thought a bit more about it, maybe they were looking for the answer "no - if you want an uninstantiable class you should do it a different way" (i.e. the way mentioned in that link).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is a standalone abstract class of any use ?
 
Similar Threads
Regarding abstract class
abstract class
abstract class
Use of constructor in abstract class?
abstract class