Access Specifiers :-
Public : The public variables and methods can be access any where and any package.
Protected : The protected variables and methods can be access same Class, same Package & sub class.
Private : The private variables and methods can be access in same class only.
Access Modifiers :-
Static :
Variable-Static int b;
Method- static void meth(int x)
1) When a member is declared as Static, it can be accessed before any objects of its class are created and without reference to any object. Eg : main(),it must call before any object exit.
2) Static can be applied to Inner classes, Variables and Methods.
3) Local variables can’t be declared as static.
4) A static method can access only static Variables. and they can’t refer to this or super
in any way.
5) Static methods can’t be abstract.
6) A static method may be called without creating any instance of the class.
7) Only one instance of static variable will exit any amount of class instances.
Final :
1) All the Variables, methods and classes can be declared as Final.
2) Classes declared as final class can’t be sub classed.
3) Method ‘s declared as final can’t be over ridden.
4) If a Variable is declared as final, the value contained in the Variable can’t be changed.
5) Static final variable must be assigned in to a value in static initialized block.
Transient :
1) Transient can be applied only to class level variables.
2) Local variables can’t be declared as transient.
3) During serialization, Object’s transient variables are not serialized.
4) Transient variables may not be final or static. But the complies allows the declaration
and no compile time error is generated.
Volatile :
1) Volatile applies to only variables.
2) Volatile can applied to static variables.
3) Volatile can not be applied to final variables.
4) Transient and volatile can not come together.
5) Volatile is used in multi-processor environments.
Native :
1) Native applies to only to methods.
2) Native can be applied to static methods also.
3) Native methods can not be abstract.
4) Native methods can throw exceptions.
5) Native method is like an abstract method. The implementation of the abstract class and native method exist some where else, other than the class in which the method is declared.
Synchronized :
1) Synchronized keyword can be applied to methods or parts of the methods only.
2) Synchronize keyword is used to control the access to critical code in multi-threaded programming.
Usage of access specifier and access modifiers:
Class - Public, Abstract, Final
Inner Class - Public, Protected, Private, Final, Static,
Anonymous - Public, Protected, Private, Static
Variable - Public, Protected, Private, Final, Static, Transient, Volatile, Native
Method - Public, Protected, Private, Final, Abstract, Static, Native, Synchronized
Constructor - Public, Protected, Private
Free-floating code block - Static, Synchronized
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment