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.
About Question enthuware.ocajp.i.v8.2.1275 :
Moderator: admin
-
- Posts: 3
- Joined: Fri Sep 09, 2016 10:57 pm
- Contact:
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1275 :
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.
thank you,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Fri Feb 01, 2019 11:36 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1275 :
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) {
}
}
}
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1275 :
Let's stay within the scope of OCAJP exam. Reflection is not on the exam.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 9 guests