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

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa

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