Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic