Solved

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

Posted on 2001-06-08
10
284 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 77
login form jsp example 2 26
eclipse console opening separately 2 21
Java Restore security prompts not working 10 13
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

803 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