Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-06-08
10
Medium Priority
?
297 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 800 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

660 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