Assuming that the method or property defaults to protected, its subclasses can also be protected, and there may be situations where these properties and methods can cause errors to be accessed properly. The interface does not know which class will be called in the future, so minimize the access control of the interface and set the permissions to public. With this in mind, Sun began to stipulate that interface properties and methods are public by default.
Example: If the protected String getName () is declared in the IPerson interface, the person implements the GetName () interface of IPerson
PackagePerson Public interface IPerson { protectedStringGetName();} PackagePerson Public class person implements IPerson{ protectedString name ="Liuzhibo";protectedStringGetName(){returnName }} PackageMan Public class man { Public Static void Main(String [] args) {Person person =NewPerson (); Person.name;//name modifier changed to public to accessPerson.getname ();//getname modifier changed to public to access}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Java keyword-interface" Why are properties and methods in an interface default to public