File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Class" Watch "Abstract Class" New topic
Author

Abstract Class

Emad Salahuddin
Greenhorn

Joined: Dec 10, 2002
Posts: 6
I know that if you have an abstract method, you need to declare the class as abstract as well. My question is that can a class be declared abstract without having any abstract methods in it.
Regards
Emad
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Yes. An example from the Java API is any of the Adapter classes in the java.awt.event package.
This will compile:
public abstract class JunkTest {}
[ June 11, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you don't want a class to be instantiated then there are two options:
1) if you want the class to be used as a parent in an inheritance hierarchy then make the class abstract (java.awt.event.FocusAdapter)
2) if you do not want the class to be used as a parent in an inheritance hierarchy then make the class final and give it a private constructor (java.lang.Math)
Emad Salahuddin
Greenhorn

Joined: Dec 10, 2002
Posts: 6
Thanks Thomas For your help.
Ma Ning
Greenhorn

Joined: Jun 16, 2003
Posts: 1
test


[img]http://data.tianmasky.com/luntan.files/photo/033.gif[/img]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Emad,
A great way to find answers to such questions is to simply code a simple example and see what the compiler has to say about it.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
Consider Paul's rocket mass heater.
 
subject: Abstract Class