Java Modifiers
Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers −
• Access Modifiers – public, private, protected and default
• Non-Access Modifiers –static, final, abstract, volatile and synchronized
Access Modifiers:
Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors.
The four access levels are:-
default: visible to package, no modifiers are needed.
public: The access level is every where…
- Inside a class
- Outside a class
- Inside a package
- Outside a package
private: The access level is only inside the class.
- Everything that is private can not be access from outside the class.
protected: Visible to the package and all subclasses.
Non–Access Modifiers
Java provides a number of non–access modifiers to achieve many other functionality
static: For creating class methods and variables.
final: For finalizing the implementations of classes, methods and variables.
abstract: For creating abstract classes and methods.
synchronized and volatile: which are used for threads.
No comments:
Post a Comment