This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract

 
muralik krishnam
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cant we create an object to a abstract class?
 
Ed Thompson
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic