Does the protected modifier protected to do this: declare a protected static member variable in an abstract class so that in each of its heirs this member would be a local static — that is, if it was changed in the descendant, it would not be changed in other descendants.
1 answer
No, it does not. In general, static variables belong to a class and cannot be inherited.
- Funny, but
class AA { public static int hello = 5; } class BB extends AA { } BB bb = new BB(); System.out.println(bb.hello); System.out.println(BB.hello);class AA { public static int hello = 5; } class BB extends AA { } BB bb = new BB(); System.out.println(bb.hello); System.out.println(BB.hello);will display the answer 5 ........ ideone.com/os1yLV - Alexey Shimansky - @ Alexey Shimansky, but this is not inheritance as such. A static class field is just like a global variable. - Nofate ♦
- @Nofate znachitsa bug%) - Alexey Shimansky
- @ AlekseyShimansky bug where? - Nofate ♦
- one@ Alexey Shimansky is not, just static fields can be accessed through the class and through the instance. - Nofate ♦
|