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 Can I Instantiate an 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 "Can I Instantiate an Abstract Class?" Watch "Can I Instantiate an Abstract Class?" New topic
Author

Can I Instantiate an Abstract Class?

Mahendran Aiyappan
Ranch Hand

Joined: Sep 05, 2005
Posts: 102
Hi guys,

I am new to Java. I want to know whether I can instantiate an Abstract class, directly or indirectly. Please provide me your useful comments.


Thanks & Regards,
Mahendran A.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14143
    
  18

Mahendran A, please check your private messages. You can see them by clicking My Private Messages.

To answer your question: No, you cannot instantiate an abstract class. An abstract class is a class that is not yet "finished" - it contains methods without an implementation. A non-abstract subclass is supposed to implement those methods.

See: The Java Tutorial - Abstract Methods and Classes.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

No abstract class can not be instantiated directly, but you can declare variables of abstract class type
[ November 16, 2007: Message edited by: sudhir nim ]

[Servlet tutorial] [Servlet 3.0 Cook Book]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

You can also create anonymous subclasses that implement all abstract methods:

These anonymous subclasses only support the constructors of the abstract class though, you can't create your own ones. If you need that kind of behaviour you need to create actual subclasses.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I Instantiate an Abstract Class?