This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Interface

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Interface can never be private or protected.
True or Faluse? Why?
 
Sheriff
Posts: 15929
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
False. Because you can have an interface inside a top-level class and declare it to be private or protected.
 
Bin Wang
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by JUNILU LACAR:
False. Because you can have an interface inside a top-level class and declare it to be private or protected.


Junilu,
Thanks. But what the purpose of "inner interface"? Could you please give me a piece of sample code?
Thanks again.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing like an inner interface. Interfaces are implicitly static
-Sandeep
------------------
www.tipsmart.com
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bin
The members of interface are always public even if it is not stated so.
Regards
Sandip
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JLS 9.1.1.1: "Every interface is implicitly abstract."
From JLS 9.1.1: "The access modifier static pertains only to member interfaces."
So interfaces are implicitly abstract, not implicitly static.
Also you can have inner interfaces, referred to in JLS 9.1.1 as "member" or "nested" interfaces. (Also JLS 8.5 says: "A member interface is an interface whose declaration is directly enclosed in another class or interface declaration.")
Sandip is correct. From JLS 9.1.4: "All interface members are implicitly public."
As for why you'd use an inner interface, I haven't run across a situation that would warrant it, so I can't give you a real-world example.
April
 
Bin Wang
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu, Sandeep, Sandip, April:
Thanks. So the answer should be True, right?
An Interface can never be private or protected.
True or False?
I still don't know what the purpose of interface within class/interface.
 
Junilu Lacar
Sheriff
Posts: 15929
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the question again. A "member" or "nested" interface CAN be protected or private. That makes the statement "An Interface can never be private or protected." FALSE.
If I recall correctly, there is at least one class or interface in the standard Java packages that has a member interface. I have no clue exactly which one it is or what it is for though, sorry.

[This message has been edited by JUNILU LACAR (edited June 21, 2001).]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while not frequently used, we still can find examples of inner interface:
Map.Entry in Map
JComboBox.KeySelectionManager in JComboBox
 
Sandeep Nachane
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point here is that there are no non-static inner,
local or anonymous interfaces (unlike classes).
See the example below.
When you define top-level nested class B, it is defined as static member of the enclosing top -level class A, but when you define an interface, explicit static declaration is not needed and in that sense interfaces are implicitly static .

-Sandeep

Originally posted by April.Johnson:
From JLS 9.1.1.1: "Every interface is implicitly abstract."
From JLS 9.1.1: "The access modifier static pertains only to member interfaces."
So interfaces are implicitly abstract, not implicitly static.
Also you can have inner interfaces, referred to in JLS 9.1.1 as "member" or "nested" interfaces. (Also JLS 8.5 says: "A member interface is an interface whose declaration is directly enclosed in another class or interface declaration.")
Sandip is correct. From JLS 9.1.4: "All interface members are implicitly public."
As for why you'd use an inner interface, I haven't run across a situation that would warrant it, so I can't give you a real-world example.
April


------------------
www.tipsmart.com
[This message has been edited by Sandeep Nachane (edited June 21, 2001).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
An interface may be private or protected but only if it is declared within a class

See JLS §9.1.1


The access modifiers protected and private pertain only to
member interfaces within a directly enclosing class declaration


So the answer to 'An interface can never be private or protected' is FALSE.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
reply
    Bookmark Topic Watch Topic
  • New Topic