SlideShare a Scribd company logo
1 of 14
01
Presented by,
Name :MD.Rakib Hossen
ID :212902020
Section :PC-212(DA)
Department: BSc.in CSE in GUB
Presented To,
DR. MUHAMMAD AMINUR RAHAMAN
Associate Professor and Campus Director,
Permanent Campus in GUB
02
What Are Access Modifiers?
In java , Access modifiers
are used to set the
accessibility (visibility) of
classes, interfaces, variables,
methods.
03
Type of Access Modifiers
 Four type of access modifiers,
1. Default
2. Public
3. Protected
4. Private
04
Default Access Modifiers
 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.
05
Default Access Modifiers
 For example,
 void math4(){
 result = a+b-c;
 System.out.println("Result by defualt modifier= "+result);
 }
 t1.math4(); //try access defualt modifiers in same class. successfully access
 t2.math4(); //try access defualt modifiers in same pacakge sub class. successfully access
 t3.math4(); //try access defualt modifiers in same pacakge non-sub class. successfully access
 //t4.mathy4; //try access defualt modifiers in Different pacakge non-sub class. not
successfully access
 //t5.mathy4; //try access defualt modifiers in Different pacakge sub class. not successfully
access
06
Public Access Modifiers
 A class or a method or a data field specified as
‘public’ is accessible from any class or package in
the Java program. The public entity is accessible
within the package as well as outside the
package. In general, public access modifier is a
modifier that does not restrict the entity at all.
07
Public Access Modifiers
 public void math1(){
 result= a+b-c;
 System.out.println("Result print by public modifier= "+result);
 }
 t1.math1(); // try access public modifiers in same class. successfully access
 t2.math1(); // try access public modifiers in same pacakge sub class. successfully access
 t3.math1(); // try access public modifiers in same pacakge non-sub class. successfully
access
 t4.math1(); // try access public modifiers in Different pacakge non-sub class.
successfully access
 t5.math1(); // try access public modifiers in Different pacakge sub class. successfully
access
08
Protected Access Modifiers
 The protected access modifiers allows access to
entities through subclasses of the class in which the
entity is declared. It doesn’t matter whether the class
is in the same package or different package, but as
long as the class that is trying to access a protected
entity is a subclass of this class, the entity is
accessible.
09
Protected Access Modifiers
 protected void math3(){
 result= a+b-c;
 System.out.println("Result by protected modifier= "+result);
 }
 t1.math3(); //try access protected modifiers in same class. successfully access
 t2.math3(); //try access protected modifiers in same pacakge sub class. successfully
access
 t3.math3(); //try access protected modifiers in same pacakge non-sub class.
successfully access
 // t4.math3(); //try access protected modifiers in Different pacakge non-sub class. not
successfully access
 t5.math3(); //try access protected modifiers in Different pacakge sub class.
successfully access
10
Private Access Modifiers
 The ‘private’ access modifier is the one that has the
lowest accessibility level. The methods and fields that
are declared as private are not accessible outside the
class. They are accessible only within the class which
has these private entities as its members.
 Note that the private entities are not even visible to
the subclasses of the class. A private access modifier
ensures encapsulation in Java.
11
Private Access Modifiers
 private void math2(){
 result=a+b-c;
 System.out.println("Resultby private modifier= "+result);
 }
 t1.math2(); //try access private modifiers in same class. successfully access
 // t2.math2(); //try access private modifiers in same package sub class. not access
successfully access
 //t3.math2(); //try access private modifiers in same package non-sub class. not access
successfully access
 //t4.math2(); //try access private modifiers in Different package non-sub class. not
access successfully access
 //t5.math2(); //try access private modifiers in Different package sub class. not access
successfully access
12
Conclusion 13
14

More Related Content

Similar to Access Modifiers .pptx

Power point presentation on access specifier in OOPs
Power point presentation on access specifier in OOPsPower point presentation on access specifier in OOPs
Power point presentation on access specifier in OOPsAdrizaBera
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
access modifier
access modifieraccess modifier
access modifiercpsivaku
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiersKhaled Adnan
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETDevLabs Alliance
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetdevlabsalliance
 
Visibility Modifiers for Access Control.pptx
Visibility Modifiers for Access Control.pptxVisibility Modifiers for Access Control.pptx
Visibility Modifiers for Access Control.pptxnaazminshaikh1727
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDevLabs Alliance
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docx3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docxcarold12
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extraNurhanna Aziz
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10Terry Yoast
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078Aravind NC
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesVinay Kumar
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++RAJ KUMAR
 

Similar to Access Modifiers .pptx (20)

Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Power point presentation on access specifier in OOPs
Power point presentation on access specifier in OOPsPower point presentation on access specifier in OOPs
Power point presentation on access specifier in OOPs
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
access modifier
access modifieraccess modifier
access modifier
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDET
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdet
 
Visibility Modifiers for Access Control.pptx
Visibility Modifiers for Access Control.pptxVisibility Modifiers for Access Control.pptx
Visibility Modifiers for Access Control.pptx
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docx3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docx
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extra
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modes
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
CHAPTER 3 part1.pdf
CHAPTER 3 part1.pdfCHAPTER 3 part1.pdf
CHAPTER 3 part1.pdf
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Access Modifiers .pptx

  • 1. 01
  • 2. Presented by, Name :MD.Rakib Hossen ID :212902020 Section :PC-212(DA) Department: BSc.in CSE in GUB Presented To, DR. MUHAMMAD AMINUR RAHAMAN Associate Professor and Campus Director, Permanent Campus in GUB 02
  • 3. What Are Access Modifiers? In java , Access modifiers are used to set the accessibility (visibility) of classes, interfaces, variables, methods. 03
  • 4. Type of Access Modifiers  Four type of access modifiers, 1. Default 2. Public 3. Protected 4. Private 04
  • 5. Default Access Modifiers  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. 05
  • 6. Default Access Modifiers  For example,  void math4(){  result = a+b-c;  System.out.println("Result by defualt modifier= "+result);  }  t1.math4(); //try access defualt modifiers in same class. successfully access  t2.math4(); //try access defualt modifiers in same pacakge sub class. successfully access  t3.math4(); //try access defualt modifiers in same pacakge non-sub class. successfully access  //t4.mathy4; //try access defualt modifiers in Different pacakge non-sub class. not successfully access  //t5.mathy4; //try access defualt modifiers in Different pacakge sub class. not successfully access 06
  • 7. Public Access Modifiers  A class or a method or a data field specified as ‘public’ is accessible from any class or package in the Java program. The public entity is accessible within the package as well as outside the package. In general, public access modifier is a modifier that does not restrict the entity at all. 07
  • 8. Public Access Modifiers  public void math1(){  result= a+b-c;  System.out.println("Result print by public modifier= "+result);  }  t1.math1(); // try access public modifiers in same class. successfully access  t2.math1(); // try access public modifiers in same pacakge sub class. successfully access  t3.math1(); // try access public modifiers in same pacakge non-sub class. successfully access  t4.math1(); // try access public modifiers in Different pacakge non-sub class. successfully access  t5.math1(); // try access public modifiers in Different pacakge sub class. successfully access 08
  • 9. Protected Access Modifiers  The protected access modifiers allows access to entities through subclasses of the class in which the entity is declared. It doesn’t matter whether the class is in the same package or different package, but as long as the class that is trying to access a protected entity is a subclass of this class, the entity is accessible. 09
  • 10. Protected Access Modifiers  protected void math3(){  result= a+b-c;  System.out.println("Result by protected modifier= "+result);  }  t1.math3(); //try access protected modifiers in same class. successfully access  t2.math3(); //try access protected modifiers in same pacakge sub class. successfully access  t3.math3(); //try access protected modifiers in same pacakge non-sub class. successfully access  // t4.math3(); //try access protected modifiers in Different pacakge non-sub class. not successfully access  t5.math3(); //try access protected modifiers in Different pacakge sub class. successfully access 10
  • 11. Private Access Modifiers  The ‘private’ access modifier is the one that has the lowest accessibility level. The methods and fields that are declared as private are not accessible outside the class. They are accessible only within the class which has these private entities as its members.  Note that the private entities are not even visible to the subclasses of the class. A private access modifier ensures encapsulation in Java. 11
  • 12. Private Access Modifiers  private void math2(){  result=a+b-c;  System.out.println("Resultby private modifier= "+result);  }  t1.math2(); //try access private modifiers in same class. successfully access  // t2.math2(); //try access private modifiers in same package sub class. not access successfully access  //t3.math2(); //try access private modifiers in same package non-sub class. not access successfully access  //t4.math2(); //try access private modifiers in Different package non-sub class. not access successfully access  //t5.math2(); //try access private modifiers in Different package sub class. not access successfully access 12
  • 14. 14