• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

abstract

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why cant we create an object to a abstract class?
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic