Can the final class have the protected attribute or method? This is a typical tip. If a class is declared as final, it indicates that the class cannot be inherited. If the class cannot be inherited, can it have protected attributes and methods?
The answer is yes. So, what is the access permission of protected?
A protected attribute or method, which can be accessed by classes in the same package or by quilt classes, but now it cannot have subclasses, at this time, protected is actually the same as the default access permission, and becomes accessible to classes in the same package.
CodeAs follows:
Package net. moon. insignificant. finalclass; </P> <p> final class finalclasssuper {<br/> protected void sayhello () {<br/> system. out. println ("Hello, world "); <br/>}</P> <p> public class finalclassdemo {<br/> Public static void main (string [] ARGs) {<br/> // todo auto-generated method stub <br/> finalclasssuper S = new finalclasssuper (); <br/> S. sayhello (); <br/>}</P> <p >}< br/>
Next article: Java tip [005]: When will the Finalize method be executed?