0% found this document useful (0 votes)
37 views

Java

Visibility control in Java determines where classes, methods, and variables can be accessed. There are four access modifiers: default, private, protected, and public. Default limits access to the same package, private to the same class, protected to the same package or subclasses, and public anywhere. A thread's lifecycle includes new, runnable, waiting, timed waiting, and terminated states as it is created, runs its task, waits for events or time, and ends.

Uploaded by

sonali dey
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Java

Visibility control in Java determines where classes, methods, and variables can be accessed. There are four access modifiers: default, private, protected, and public. Default limits access to the same package, private to the same class, protected to the same package or subclasses, and public anywhere. A thread's lifecycle includes new, runnable, waiting, timed waiting, and terminated states as it is created, runs its task, waits for events or time, and ends.

Uploaded by

sonali dey
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Visibility Control In JAVA

&
Life cycle of thread
Visibility Control In JAVA

 Java access modifiers are known as Visibility Control in Java.

 Modifiers are used to define where members, function and class can be used and
where these can’t be accessed .

There are four types of access modifiers available in java: 

 Default – No keyword required

 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.

 Any other class of the same package will not be able to access these members.

 Top-level classes or interfaces can not be declared as private because

• private means “only visible within the enclosing class”.

• protected means “only visible within the enclosing class and any subclasses”
Protected:
 The protected access modifier is specified using the keyword protected.

 The methods or data members declared as protected are accessible within


the same package or subclasses in different packages.

Public:

•The public access modifier is specified using the keyword public.


 

• The public access modifier has the widest scope among all other access
modifiers.

• Classes, methods, or data members that are declared as public are accessible


from everywhere in the program. There is no restriction on the scope of public
data members.
Life cycle of Thread

Following are the stages of the life cycle −


 New − A new thread begins its life cycle in the new state. It remains in this state until the
program starts the thread. It is also referred to as a born thread.

 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.

   Terminated (Dead) − A runnable thread enters the terminated state when it


completes its task or otherwise terminates.

You might also like