I cleared OCA and started to prepare for OCP. I am having a hard time understanding the concepts given in Page 3 of OCP
Java 8 Programmer II Stude Guide.
We have a class BigCat.
There is another class Lynx in another package which extends BigCat
There is another class CatAdmirer within the same package "cat"
Question 1:
According to the book, this line will not compile as we are accessing it via a variable and so it does not benefit from protected. If I make hasFur variable static in BigCat, I can access the variable.
Why does the code not compile when the variable is non-static and why the code compiles fine when the variable is static?
I am accessing hasFur using a variable in both cases.
Question 2:
Here, I am accessing hasPaws via variable too. If protected variables are not visible when accessed via variable why is package-private variable visible when access via variable?
Please help.