aspose file tools*
The moose likes Beginning Java and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class" Watch "Abstract class" New topic
Author

Abstract class

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Aug 03, 2008
Posts: 9280
    
  17

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....


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2712
    
    5

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


SCJP, SCWCD.
|Asking Good Questions|
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
I don't think that is actually a mistake, Amit, but ambiguous grammar.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2712
    
    5

Can't say for sure but lets say its grammar problem (since its posted by a SCJP )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class
 
Similar Threads
ABSTRACT
A question about container!
usage of a class
A mock question
HttpServlet class