It's not a secret anymore!
The moose likes Beginning Java and the fly likes abstract Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract" Watch "abstract" New topic


muralik krishnam

Joined: Oct 19, 2007
Posts: 3
why cant we create an object to a abstract class?
Ed Thompson
Ranch Hand

Joined: Jan 20, 2006
Posts: 43
An abstract class generalizes but does not define behavior. You can not instantiate (create) an abstract class by definition the 'how' of some behavior is yet to be defined.

Why would you want to, and maybe we can help find an alternative design?

Even if the voices <i>aren't</i> real, they still have some good ideas!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

Abstract means a couple things in Java. One is you can't make an instance. So the reason you can't make an instance is because that's what the designers decided abstract means.

The other thing it means is the class is allowed to be incomplete. It might say it implements an interface but doesn't implement all the methods. Or it might declare a method signature without a method body.

It's often handy to provide a partial implementation but require some subclass to fill in the missing bits. For example, the documentation for AbstractList says This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array). It just makes life easier for someone who wants implement List.
[ October 19, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: abstract
It's not a secret anymore!