File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,
i tried a class with abstract modifier without declaring any abstract methods.It's working.then what is the use of Abstract there.
it is also possible to define constructors for abstract classes.but we don't create objects to Abstract classes.then why?


Thanks
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can declare a class abstract but still have non-abstract methods and constructors in it.

It's very useful because you could define a certain set of behaviors, but leave one or more behaviors undefined. You would then have to create a concrete subclass that defined the behaviors that the superclass didn't if you want to create an instance of it, but they would inherit the behavior(s) that the superclass defined.
Douglas Chorpita
Ranch Hand

Joined: May 09, 2006
Posts: 97
The question is a good one.

You can define a class as abstract because you don't want anyone to instantiate it (because it really is not a "mature" class).

At the same time, you can define default implementations for ALL the methods. A class that subclasses this class isn't forced to override anything specific. Nevertheless, it is IMPLIED (but not required) that some methods, but any specific methods SHOULD be overridden.


SCJP 1.4 - 95%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract class
 
Similar Threads
ABSTRACT
HttpServlet class
A question about container!
usage of a class
A mock question