This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why private interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why private interface" Watch "why private interface" New topic

why private interface

lee nelson

Joined: Sep 25, 2000
Posts: 2
hi guys,
Can any one tell me what's the use of an private and
protected interface
Ramesh Donnipadu
Ranch Hand

Joined: Sep 16, 2000
Posts: 100
Top level (package level) interfaces are public by default. This is trye even if you don't explicitly define any modifier. You can't define private/protected interfaces at package level.
However, interfaces defined inside a class can have any accessibility including protected and private. Let us see where these can be used.
Supposing A be top level class and IFace be inner interface defined with private modifier. Then all inner classes defined inside class A can inherit IFace. Subclasses of A cannot define inner classes that implement IFace.
With protected modifier subclasses of A can define inner classes which can implement IFace.
I agree. Here's the link:
subject: why private interface
It's not a secret anymore!