0
protected access specifier allows access to the super class(i.e., the class which is declared as protected) and provides access only to the first level of inheritance(i.e., the base class which is first derived from the protected super class). isn't it?..
3 Respuestas
0
The protected method is accessible from within its package, and also from outside its package by subclasses of the class containing the method.
The protected data member is accessible within its package, and also from outside its package by subclasses of the class containing the data member.
Source: java 7 pocket guide book.
0
could you give me an example?.
0
class Test{
protected int age; // age field is accessable from all classes in the current package and all subclasses from other packages.
}
public class Program
{
public static void main(String[] args) {
Test t = new Test();
t.age = 24;// age field is accessable because both classes (Test and Program) in the same package
System.out.println(t.age);
}
}