About Question enthuware.ocajp.i.v7.2.856 :
Posted: Thu Nov 13, 2014 11:43 am
Question:
Answer:
The answer is partially correct because you can read and modify if you are in the same package.
However if there is a class in another package which extends MyClass it can only inherit the variable, but it can read or modify the value of a variable of a MyClass instance.
Code: Select all
Consider the following code:
public class MyClass {
protected int value = 10;
}
Which of the following statements are correct regarding the field value?
Code: Select all
It can be read and modified from any class within the same package or from any subclass of MyClass.
However if there is a class in another package which extends MyClass it can only inherit the variable, but it can read or modify the value of a variable of a MyClass instance.