answersLogoWhite

0

They can't be private...what's the point of a private interface method? It can't be called by anything.

It can't be protected for a similar reason. Interfaces are simply for exposing public functionality to other classes. If you want protected status, then create a new class and inherit the methods, because protected restricts access to the class tree I guess you have to stand back and look at what the "Interface" design is for. It is to allow objects that possibly come from different packages and even vendors (this is the basis for J2EE design and implementation) to interoperate with a known reference point.

If you need to hide methods between your own modules (which this appears, to me, to be your problem) then you should be able to accomplish it with an Abstract Class and get around your issues? Of course, you can also use the default (no) access modifier to allow only package classes and subclasses to call the methods of an interface.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

ReneRene
Change my mind. I dare you.
Chat with Rene
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake

Add your answer:

Earn +20 pts
Q: Why does Java Force Interface Methods to be Public?
Write your answer...
Submit
Still have questions?
magnify glass
imp