answersLogoWhite

0


Best Answer

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

โˆ™ 2009-08-09 20:18:46
This answer is:
User Avatar
Study guides

Mixture

1 card

Class

โžก๏ธ
See all cards
4.35
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
23 Reviews

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
Related questions

What implicit modifiers interface methods have in java?

public


What is intrface in java?

interface is a list of methods which implements that interface


How many methods are there in the ActionListener interface in java?

there is one method only. go to command prompt and type this to know the methods. D:\java>javap java.awt.event.ActionListener Compiled from "ActionListener.java" public interface java.awt.event.ActionListener extends java.util.EventListener{ public abstract void actionPerformed(java.awt.event.ActionEvent); }


What is a tagging interface type?

A tagging interface type in Java is an interface that has not defined methods such as the java.io.Serializable interface.


What is interface in java?

Interface is collection of abstract methods which has only declaration and no implementation


When you implement an interface method it should be declared as public in java?

This is not necessarily true. The only rules for this are that interface methods may not be private. They may be public, protected, or have the default (blank) access modifier.


What do mean by interface in java?

An interface in Java is like an abstract class, but there are no method bodies allowed in it and it has to be declared with the interface keyword. It is Java's way of getting around the Deadly Diamond of Death. Only abstract methods and constants are allowed in it.


What kind of constructs can be declared in a Java interface?

Constants and abstract methods. That's it.


Write a program in java interface for calculating area?

interface Shape { public double getArea(); }


What if a final keyword is applied to an interface?

You cannot. An Interface can be only public or abstract. A final keyword indicates - the methods cannot be overridden whereas in an interface you expect the implementing class to write all the methods. So logically it shouldn't be possible which Java does. When you compile a interface with final keyword - the compiler wont let you compile.


Can interface implements another interface in java?

Implements denotes defining an implementation for the methods of an interface. However interfaces have no implementation so that's not possible. An interface can however extend another interface, which means it can add more methods and inherit its type.


What is the major difference between an Interface and a Class?

An interface can only have abstract methods or constants in it. A class can have both that and everything else in Java.

People also asked