This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class

 
satya sahu
Ranch Hand
Posts: 97
  • 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
  • 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: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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: 3913
9
Chrome Fedora Hibernate
  • 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: 2854
10
Fedora Firefox Browser Java
  • 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
Posts: 48438
56
  • 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: 2854
10
Fedora Firefox Browser Java
  • 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 )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic