Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why cannot interface defined inside a public class have protected methods??  RSS feed

 
vaishali shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I needed some clarification. If i had a class say abcd in file abcd.java. Its possible to defined an interface xyz in it only it cannot be defined as public. ie to say that the interface would have package access. If this is the case why cant i have method in the interface which are protected.
public class abcd{


}

interface xyz{

}
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface methods are implicitly public and abstract. They cannot have any other modifier than public, and you cannot say, for instance, "final void doThis();" in an interface, because it's implicitly abstract.

Default access for the interface itself is allowed, however.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!