0

what is protected keyword in the classes?

11th Nov 2016, 1:53 PM
Ayin GhaziMoradi
3 Answers
+ 4
any protected attribute can be accessed by the class itself and any class that inherit that class but cannot be accessed otherwise
11th Nov 2016, 2:01 PM
Burey
Burey - avatar
+ 2
protected method or attribute can only be accessed withing parent class or subclass e.g let's say you have Class Foo { protected String name = "some text"; public String void myFunc(){ //code here } } class Bar extends Foo{ public static void main(String args[]){ System.out.println(new Foo().name); } } //Output: some text but if you try to access name attribute in class that is not a subclass of Foo you will get error.
11th Nov 2016, 2:16 PM
ARB
ARB - avatar
0
thank you all my friends!
11th Nov 2016, 2:24 PM
Ayin GhaziMoradi