Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Can I Instantiate an Abstract Class?  RSS feed

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21464
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.
 
I'm full of tinier men! And a tiny ad:
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!