• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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: 9709
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: 80775
489
  • 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 )
 
reply
    Bookmark Topic Watch Topic
  • New Topic