What is non access modifier? | Core Java Forum
V
Vikrant Posted on 17/07/2021

Hi Yogesh,

 

Please describe about non-access modifier. It has been asked to me in an interview?

 

Thanks,

Vikrant


M
Replied on 18/07/2021

Hi,  These are the non access modifiers in java:

static, final, abstract, synchronized, transient and volatile

Static - we have covered in detail as part of Module 5. In nutshell, static keyword is used so that variables and methods can be shared by all instances of a class or classes. 

final - we have covered in detail as part of Module 7. In nutshell, we use final keyword so as to stop variable, method and class functionality from getting changed apart from all other rules which we need to adhere to.

abstract - we have covered in detail as part of Module 3. Abstraction helps every project to have one class which
has both common as well as unique functionality which other classes can use and define according to the business requirement.

synchronized - we have covered in detail as part of Multi Threading module. Synchronization helps variables or methods to be executed by one thread at a time so that no thread interference or inconsistency issues comes as part of project.

transient keyword is used to avoid serialization.
If any object is defined as a transient then it can't be serialized where Serialization is the ?process of converting an object into a byte stream. This we have covered as part of Files module.

Volatile keyword is used to modify the value of a variable by different threads. It is also used to make classes thread safe. It means that multiple threads can use a method and instance of the classes at the same time without any problem.This is also covered as part of Multi-Threading module.