Page 1 of 1
About Question enthuware.ocajp.i.v8.2.1275 :
Posted: Sun Sep 11, 2016 9:06 pm
by Hissam
It clearly says
How can you declare 'i' so that it is not visible outside the package test.
that implies it should be visible inside the package.
Re: About Question enthuware.ocajp.i.v8.2.1275 :
Posted: Sun Sep 11, 2016 10:04 pm
by admin
I am sorry I do not agree that there is any such implication. All it means and implies that i should not be visible outside the package test. It doesn't say anything about inside the package.
thank you,
Paul.
Re: About Question enthuware.ocajp.i.v8.2.1275 :
Posted: Fri Feb 01, 2019 1:53 pm
by Hansolo
Code: Select all
// Yoda: Do or do not there is no try
package have;
public class TheGoods {
private String forEyesOnly = "I am supposed to be private";
}
Code: Select all
package havenot;
import java.lang.reflect.Field;
import have.TheGoods;
public class AccessTester {
public static void main(String[] args) {
TheGoods theGoods = new TheGoods();
try {
Field field = TheGoods.class.getDeclaredField("forEyesOnly");
field.setAccessible(true);
String answer = (String)field.get(theGoods);
System.out.println( answer + " but anyone can read it if they really want to.");
} catch (Exception e) {
}
}
}
Re: About Question enthuware.ocajp.i.v8.2.1275 :
Posted: Fri Feb 01, 2019 7:26 pm
by admin
Let's stay within the scope of OCAJP exam. Reflection is not on the exam.