0

Possible Duplicate:
Interfaces in Java: cannot make implemented methods protected or private

By default all the methods in interface are public and abstract. We can't define private method in interface because its scope will be inside the interface itself. So private is meaningless resulting Compile time error.

Now the questions comes why can't we have protected?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ankur
  • 53
  • 1
  • 2
  • 1
    What do you expect the effect of a protected method in a public interface would be? Conversely, what are you trying to achieve that a package-private interface couldn't? – Daniel Pryden Jan 21 '13 at 05:15
  • 4
    I guess it defeats the purpose of "Interface" – Karthik T Jan 21 '13 at 05:15
  • @DanielPryden: A package-private interface still requires that all of its methods, and consequently all of their implementations, be public. – ruakh Jan 21 '13 at 05:24
  • In the case of CLASS-Protected methods can be overridden in the same package or through any of the sub class in different package. Why not the same functionality in case of inteface – Ankur Jan 21 '13 at 08:13
  • 1
    An interface defines only how a component can be used. It does not imply how it is implemented. – Peter Lawrey Jan 21 '13 at 09:12

0 Answers0