• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract class

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can there be an abstract class with no abstract methods in it?
If the answer is yes, then what is the use of such class?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by satya sahu:
Can there be an abstract class with no abstract methods in it?
If the answer is yes, then what is the use of such class?



abstract class can have non-abstract methods only.

If the answer is yes, then what is the use of such class?

answare:abstract methods do not have body

Hope This Helps
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes there can be abstract class with no abstract methods in it....

there can be one use of it....if you don't want someone to create instances of your class without extending it.....I think this is the only use but I don't think we need this kind of thing in real life....
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it's fine to declare a class as abstract with no abstract methods in it. By doing so it is not possible to instantiate an object from that class but extends it. That's the only usage I see. May be someone else has a better idea.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
abstract class can have non-abstract methods only.


Its wrong, abstract class can have both abstract as well as non abstract methods.

As pointed out by Ankit, use of such class is to let others extend it before making its instances.One such well known class is the javax.servlet.http.HttpServlet.

Hope this helps
 
Marshal
Posts: 79405
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that is actually a mistake, Amit, but ambiguous grammar.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't say for sure but lets say its grammar problem (since its posted by a SCJP )
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic