Solved

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

Posted on 2001-06-08
10
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Expert Comment

by:smileyxx
ID: 6169295
"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
ID: 6171081
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
ID: 6172718
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:webaski
ID: 6174044
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
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 6177676
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
ID: 6182679
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
ID: 9062071
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
ID: 9072444
Recommendation: points to jim_cakalic
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9253893
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
throw exception 21 78
Running JavaFX on JDeveloper 12C 1 116
JavaFX TableView not displaying correctly 3 162
How to convert from xls to xlsx using java 7 159
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Suggested Courses

751 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