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

Day 2

Java provides four access modifiers: public, private, protected, and default. Public members can be accessed anywhere, private members can only be accessed within their class, protected members can be accessed within their package or subclasses outside the package, and default members can only be accessed within their package with no specified keyword. Access modifiers determine the visibility and accessibility of classes, methods, and variables to control encapsulation and reusability in object-oriented programming.

Uploaded by

May Sandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Day 2

Java provides four access modifiers: public, private, protected, and default. Public members can be accessed anywhere, private members can only be accessed within their class, protected members can be accessed within their package or subclasses outside the package, and default members can only be accessed within their package with no specified keyword. Access modifiers determine the visibility and accessibility of classes, methods, and variables to control encapsulation and reusability in object-oriented programming.

Uploaded by

May Sandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Java Access Modifier

Day-2
Access Modifier in Java
• Access Modifiers In Java
• The access specifiers also determine which data members (methods or fields) of a class can be
accessed by other data members of classes or packages etc. To ensure encapsulation and
reusability, these access specifiers/modifiers are an integral part of object-oriented programming.
• Modifiers in Java are of two types:
• #1) Access Modifiers
• Access modifiers in Java allow us to set the scope or accessibility or visibility of a data member
be it a field, constructor, class, or method.
• #2) Non-access Modifiers
• Java also provides non-access specifiers that are used with classes, variables, methods,
constructors, etc. The non-access specifiers/modifiers define the behavior of the entities to the
JVM.
Some of the non-access specifiers/modifiers in Java are:
•static
•final
•abstract
•transient
•volatile
•synchronized
•native
Types Of Access Modifiers In Java
• Java provides four types of access specifiers that we can use with classes and other entities.
• These are:
• #1) Default: Whenever a specific access level is not specified, then it is assumed to be
‘default’. The scope of the default level is within the package.
• #2) Public: This is the most common access level and whenever the public access specifier
is used with an entity, that particular entity is accessible throughout from within or outside
the class, within or outside the package, etc.
• #3) Protected: The protected access level has a scope that is within the package. A protected
entity is also accessible outside the package through inherited class or child class.
• #4) Private: When an entity is private, then this entity cannot be accessed outside the class.
A private entity can only be accessible from within the class.
We can summarize the access modifiers in the following table.
Default Access Specifiers
• A default access modifier in Java has no specific keyword. Whenever
the access modifier is not specified, then it is assumed to be the
default. The entities like classes, methods, and variables can have a
default access.
• A default class is accessible inside the package but it is not accessible
from outside the package i.e. all the classes inside the package in
which the default class is defined can access this class.
• Similarly a default method or variable is also accessible inside the
package in which they are defined and not outside the package.

You might also like