This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why we can't create object to ABSTRACT & INTERFACE classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why we can Watch "Why we can New topic

Why we can't create object to ABSTRACT & INTERFACE classes?

chenna kesava koyyagura

Joined: Nov 25, 2007
Posts: 3
Hi, friends please tell me why we can't create objects to abstract classes as well as interface classes?

please help me.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
This question makes no sense, but is almost certainly not an Advanced question. Please choose your forum more carefully.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Simply said, because it is possible that some methods are not implemented. In the case of an interface, non of the methods are implemented.

If you would be able to create an instance, and call a non-implemented method, what code should be executed? Not that of the class / interface itself, since there is no code to execute.

How To Ask Questions How To Answer Questions
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
To Rob's point, the abstract keyword is the way the author of a class tells readers and users that it is not complete and ready to use. Kind of like "Some assembly required" on the box a toy comes in.

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
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Here's what I think your question is:

"Why can't you instantiate an interface or an abstract class?"

The short answer: because that's how they are defined.


Instantiate - to create one instance of a class. The newly created object is a "kind of" the class.

Interface - a declaration of methods that are expected of a class. If the class declares they implement the interface, it must provide implementations for all the methods declared by the interface.

Abstract Class - a class that cannot be instantiated. Often it will include one or more methods that are also declared abstract and must be implemented by subclasses for the subclass to be concrete (opposite of abstract), and therefore able to be instantiated. Does not have to include abstract methods; the documentation may otherwise specify what is required of a valid concrete subclass.

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: Why we can't create object to ABSTRACT & INTERFACE classes?
It's not a secret anymore!