Possible Duplicate:
JVM/Java, are method accessibility rules enforced at runtime?
When using a class that has both public and private fields and members, is the code checked for access violations (e.g. trying to access a private field from an outside class) at compiled time or run time? Or both?
Both. If you try to compile code which tries to access inaccessible object or method, you'll get compile-time error:
field has private access in package.Class
Also, when your class tries to access some field at runtime, JVM checks the access:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field package.Class.field from class YourClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With