• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can I Instantiate an Abstract Class?

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic