| 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
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
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: 19232
|
|
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
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Can I Instantiate an Abstract Class?
|
|
|