File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class

 
satya sahu
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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....
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that is actually a mistake, Amit, but ambiguous grammar.
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't say for sure but lets say its grammar problem (since its posted by a SCJP )
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic