The access modifiers place a vital role in java programming.
The list of various modifiers available in java is as follows:
The interface which is declared inside an interface is always public and static implicitly.
The class which is declared inside an interface is always public and static implicitly.
Variables:The list of various modifiers available in java is as follows:
- public
- private
- protected
- <default>
- abstract
- final
- static
- native
- synchronized
- strictfp
- transient
- volatile
Modifiers and their applicability |
Important Conclusions:
- The modifiers wihich are applicable for inner classes but not outer classes are private, protected, static.
- The modifier that is applicable to class but not interface is final
- The modifiers that are applicable to classes but not enums are final and abstract.
- The modifier which is applicable to only methods and cannot be used anywhere else is native.
- The only modifiers which are applicable to constructors are public,private,protected, default.
- The only applicable modifier for local variables is final.
- a class inside a class
- a class inside an interface
- an interface inside an interface
- an interface inside a class.
The interface which is declared inside an interface is always public and static implicitly.
The class which is declared inside an interface is always public and static implicitly.
Illegal Combinations :
Methods:
- If a method is public, we cannot declare it as private or protected.
- If a method is abstract, then we cannot declare it as final, static, private, synchronized, strictfp, native.
- If a variable is public, we cannot declare it as private or protected.
- If a variable is final, we cannot declare it as volatile.
- If a class is public, we cannot declare as private or protected.
- If a class is final, we cannot declare as abstract.
No comments:
Post a Comment