Link to home
Start Free TrialLog in
Avatar of webaski
webaski

asked on

abstract interface, why to specify abstract (an interface is abstract !!)?

In some packages, we find some interfaces declared as abstract.
For exemple:
public abstract interface Synchronization

An interface is a file of abstract methods (signatures only), so why to specify abstract?
Is it necessary?
Does it mean something?
Avatar of smileyxx
smileyxx

"All methods of an interface are implicitly abstract, even if the abstract modifier is omitted." Java in a Nutshell

So, it is not necessary, and does not mean anything to an interface.
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Webski

U can create an instance for an Interface that is quite possible. But for a abstract interface u cann't. That is why some interface cann't have instance that is why to avoid them there use abstract before it.


Cheers
Shyam
Avatar of webaski

ASKER

Hi Shyam,
How can you create an instance of an interface, when you only have the signatures of the methods in it?
It is not possible... Is it?
You're right, webaski, you cannot create an instance of an interface in the same way you create an instance of a class. For example, the following will not work:

    Serializable x = new Serializable();

Being _inherently_ abstract, you cannot directly create instances of an interface, just as you cannot construct instances of an abstract class. But you might, through an anonymous inner class, declare a class that implements the interface, define that class's implementation, and construct an object of the new class.

    Serializable x = new Serializable() { };

This _looks_ a lot like creating an instance of an interface but is _completely_ different.

Best regards,
Jim Cakalic
Avatar of webaski

ASKER

Well, it works because there is no method in the Serializable interface... Try with WindowListener for example, it won't compile.

WindowListener x = new WindowListener() { };
webaski:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Recommendation: points to jim_cakalic
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to jim_cakalic]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.