Java
Java
&
Life cycle of thread
Visibility Control In JAVA
Modifiers are used to define where members, function and class can be used and
where these can’t be accessed .
Private
Protected
Public
Default:
When no access modifier is specified for a class, method, or data member – It is said to be having
the default access modifier by default.
The data members, class or methods which are not declared using any access modifiers i.e. having
default access modifier are accessible only within the same package.
Private
:
The private access modifier is specified using the keyword private.
The methods or data members declared as private are accessible only within the class in
which they are declared.
• protected means “only visible within the enclosing class and any subclasses”
Protected:
The protected access modifier is specified using the keyword protected.
Public:
• The public access modifier has the widest scope among all other access
modifiers.
Runnable − After a newly born thread is started, the thread becomes runnable. A thread in
this state is considered to be executing its task.
Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for
another thread to perform a task. Thread transitions back to the runnable state only when
another thread signals the waiting thread to continue executing.
Timed Waiting − A runnable thread can enter the timed waiting state for a specified
interval of time. A thread in this state transitions back to the runnable state when that
time interval expires or when the event it is waiting for occurs.