OOPS in JAVA 10
Modifiers in Java
Modifiers are keywords that are added to change meaning of a definition. In Java, modifiers are catagorized into two types,
Access control modifier
Non Access Modifier
1. Access control modifier
Java language has four access modifier to control access levels for classes, variable methods and constructor.
Default : Default has scope only inside the same package
Public : Public scope is visible everywhere
Protected : Protected has scope within the package and all sub classes
Private : Private has scope only within the class
1. Non-access Modifier
Non-access modifiers do not change the accessibility of variables and methods, but they do provide them special properties.
Final : Final modifier is used to declare a field as final i.e. it prevents its content from being modified. Final field must be initialized when it is declared.
Static : For creating class variables and class methods which can be accessed without instance of a class(object).
Abstract : For a class, it cannot be directly instantiated, but has to be subclassed. A method does not have an implementation in the class, but has to be implemented in a subclass.
Transient : When an instance variable is declared as transient, then its value doesn't persist when an object is serialized.
Synchronized : When a method is synchronized it can be accessed by only one thread at a time.
Volatile : Volatile modifier tells the compiler that the volatile variable can be changed unexpectedly by other parts of your program. Volatile variables are used in case of multithreading program.
No comments:
Post a Comment
Hai , Post your comment . (required, Bugs, Errors )