Solved

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

Posted on 2001-06-08
10
282 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:webaski
10 Comments
 

Expert Comment

by:smileyxx
Comment Utility
"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.
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 200 total points
Comment Utility
The Java Language Spec 2.0 advises "Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs." With respect to methods declared in an interface, it goes on to state, "For compatibility with older versions of Java, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces."

So using abstract in the definition of an interface in no way distinguishes it from an interface _not_ declared with the abstract modifier. There is no difference between the two.

Evidently, sometime in the dim and distant path, it was required that interfaces and defined methods be declared using the abstract keyword. As it was eventually recognized that this declaration was redundant, that requirement was relaxed. However, for purposes of compatibility with legacy releases of the JDK, the syntax is still acceptable to modern compilers. Seeing as this change came about even prior to the publication of the JLS 1.0 in 1996, it is highly unlikely, although possible, that you would run into a compiler that required the abstract keyword in the declaration of either an interface or its methods.

Best regards,
Jim Cakalic
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
Comment Utility
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
0
 

Author Comment

by:webaski
Comment Utility
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?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 19

Expert Comment

by:Jim Cakalic
Comment Utility
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
0
 

Author Comment

by:webaski
Comment Utility
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() { };
0
 

Expert Comment

by:CleanupPing
Comment Utility
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.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
Comment Utility
Recommendation: points to jim_cakalic
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
return in catch statement 1 40
Python Assistance 7 31
@SBGen Method 3 25
Non-recursive backtracking, using a stack 1 48
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now