All these private, public, protected or no-access modifiers(default)
are just a concept to develop to do coding in well organize manner.
You can find some good information from here. The answer you are looking is there.
But there is no such protection, hidden information using any of these modifiers in Java
Consider following code
public class ProtectedPrivacy{
private String getInfo1(){
return "private";
}
protected String getInfo2(){
return "protected";
}
String getInfo3(){
return "default";
}
public String getInfo4(){
return "public";
}
}
Any access level you can violate as follows
public class BreakModifires{
public static void main(String[] args) throws Exception {
ProtectedPrivacy protectedPrivacy = new ProtectedPrivacy();
Method method = protectedPrivacy.getClass().getDeclaredMethod("getInfo*", null);
method.setAccessible(true);
Object result = method.invoke(protectedPrivacy);
System.out.println(result.toString());
}
}