1.

What Is The Protected Method Modifier?

Answer»

Using the public, private and protected keywords, you can control a variable's scope. In a similar WAY, Java lets you USE these attributes with class methods as well. A protected method is only visible within its class, within subclasses or within the class package. To DECLARE a method as protected, simply precede the method header with the protected KEYWORD, as SHOWN:

protected int myProtectedMethod();

Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A protected method is only visible within its class, within subclasses or within the class package. To declare a method as protected, simply precede the method header with the protected keyword, as shown:

protected int myProtectedMethod();



Discussion

No Comment Found