This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Is a standalone abstract class of any use ?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for replying.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect they're thinking of a Utility - i.e. a class that only has static methods. For example, java.lang.Math.
 
Marshal
Posts: 74687
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Utility classes are not usualloy abstract. They are usually unintantiable.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic