Some Quick Reference points about Declaration and Access control for Java Job Interviews
1. A method marked as ‘private’ can’t be overridden. This does not mean that we cannot have a method with same name and signature in the subclass.
2. For a sub class outside the package, the protected member can be accessed only through inheritance. i.e the protected members cannot be accessed by its sub classed outside the package using the reference of a super class.
3. We cannot apply any access modifiers to local variables. The only modifier that can be applied to local variable is ‘final’.
4. ‘ synchronized’ modifier can only be applied to methods or a block of code inside a method.
5. ‘synchronized’ modifier indicates that the methods or block of code to make sure that only one thread accesses the code at a time.
6. ‘native’ modifier indicates that the method is implemented in a platform dependent language such as C.
7. ‘native’ can be applied only to methods.
8. ‘strictfp’ modifier can be applied to classes and methods.
9. ‘strcitfp’ modifier forces floating point literals to adhere to the IEE754 standars.
10. ‘transient’ and ‘volatile’ modifier can be applied only to instance variables.
11. ‘transient’ variables are ignored during serialization of the objects.
12. The volatile modifier tells the JVM that a thread accessing the variable must always reconcile its own private copy of the variable with the master copy in memory.
No comments:
Post a Comment