• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

interface implements

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was reading the K&B book and interfaces are said to be implicitly abstract. They can also have two access levels: public and default. My first question is:
Is it correct that interfaces cannot be private or protected?

Secondly, because I see that interfaces can have package access level, does that mean that interfaces can belong to a particular package? So we can add statement to an interface file?

If the answer is yes, interfaces can belong to a package then can we use when an interface wants to extend another interface.

Hopefully the questions are clear and will make sense.

Thanks.
 
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to all your questions is yes.

There is one extra thing you may be interested to know, which is that an interface can be nested within a class, and in that case it can be declared protected or private. But I do not know whether this is necessary to know for the exam.
 
kawshik java
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dennis Deems wrote:The answer to all your questions is yes.

There is one extra thing you may be interested to know, which is that an interface can be nested within a class, and in that case it can be declared protected or private. But I do not know whether this is necessary to know for the exam.



Thanks. I haven't yet come across interfaces nested inside a class. Fingers crossed.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You will see this kind of question which will show interface nested inside a class
 
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dennis Deems

You told a very interested point 'nested interface can be private or protected in a class' and i want to what the purpose of it???
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the answer to your Question
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is one more thing

A nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface.

 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aashu Mahajan wrote:Hi Dennis Deems

You told a very interested point 'nested interface can be private or protected in a class' and i want to what the purpose of it???



I have never found any use for it in my own code, and no one has been able to show me an example that seemed useful. It's just one of those things the language allows us to do. :/
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dennis Deems wrote:But I do not know whether this is necessary to know for the exam.



Hello Dennis...Hello Ranchers
I guess it is necessary to know that interfaces can be nested for the purpose of the exams. They can even be declared within enums!

Its one of the many TRIP-TRAPS
you may find in the exams.
 
I am displeased. You are no longer allowed to read this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!