SlideShare a Scribd company logo
1 of 11
ACCESS MODIFIER AND
INHERITANCE
DEFINATION OF ACCESS MODIFIER
• It is simply a keyword in java that provides accessibility of a class and its members.
• Set in the access level to method, variable, classes and constructors.
• Classification of access modifier are:-
• Private
• Protected
• Public
PRIVATE ACCESS MODIFIER
• It is the most restrictive access level whereby they are accessible only within the class itself.
• A superclass private members are not inherited by its subclasses.
• Example of Private Access Modifier is:
PROTECTED ACCESS MODIFIER
• It can be accessed by only the class of same package and the subclass present in any package.
• It has visibility in sub classes and Classes cannot be declared as protected.
• Example of Protected Access Modifier:
PUBLIC ACCESS MODIFIER
• It can be access with any classes.
• It is widest scope among all other modifiers.
• Example of Public Access Modifier is:
SCOPE OF ACCESS MODIFIERS IN TABULAR FORM
Access
Modifier
Within
Class
Within
Package
Outside Package By
Subclass only
Outside
Package
Private Y N N N
Protected Y Y Y N
Public Y Y Y Y
ACCESS MODIFIER AND INHERITANCE
• Inherits features of parent’s object/class to the child’s object/class.
• Extends keyword is used to inherit the features of superclass.
THANK YOU!!

More Related Content

Similar to Access modifier and inheritance

Access Specifier and encapusulation.pdf
Access Specifier and encapusulation.pdfAccess Specifier and encapusulation.pdf
Access Specifier and encapusulation.pdf
SunithaKrishnan9
 
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
LearningTech
 
Access Protection
Access ProtectionAccess Protection
Access Protection
myrajendra
 

Similar to Access modifier and inheritance (20)

Java Access Specifier
Java Access SpecifierJava Access Specifier
Java Access Specifier
 
Access Specifier and encapusulation.pdf
Access Specifier and encapusulation.pdfAccess Specifier and encapusulation.pdf
Access Specifier and encapusulation.pdf
 
Access Modifiers .pptx
Access Modifiers .pptxAccess Modifiers .pptx
Access Modifiers .pptx
 
Java introduction
Java introductionJava introduction
Java introduction
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
D2 Object Oriented Programming
D2 Object Oriented ProgrammingD2 Object Oriented Programming
D2 Object Oriented Programming
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In Java
 
27c
27c27c
27c
 
27csharp
27csharp27csharp
27csharp
 
Chap1 packages
Chap1 packagesChap1 packages
Chap1 packages
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
Chapter 7 & 8 Classes in Java and Functions.pdf
Chapter 7 & 8 Classes in Java and Functions.pdfChapter 7 & 8 Classes in Java and Functions.pdf
Chapter 7 & 8 Classes in Java and Functions.pdf
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Access Protection
Access ProtectionAccess Protection
Access Protection
 
Differentiate between class Derived -public Base and class Derived- pr.docx
Differentiate between class Derived -public Base and class Derived- pr.docxDifferentiate between class Derived -public Base and class Derived- pr.docx
Differentiate between class Derived -public Base and class Derived- pr.docx
 

More from Dikshyanta Dhungana

More from Dikshyanta Dhungana (9)

Punctuation
PunctuationPunctuation
Punctuation
 
Heuristic evaluation
Heuristic evaluationHeuristic evaluation
Heuristic evaluation
 
Building learning organization
Building learning organizationBuilding learning organization
Building learning organization
 
Daily stand up meeting
Daily stand up meetingDaily stand up meeting
Daily stand up meeting
 
Stlc and v model
Stlc and v modelStlc and v model
Stlc and v model
 
Agile manifesto
Agile manifestoAgile manifesto
Agile manifesto
 
Functional and non functional
Functional and non functionalFunctional and non functional
Functional and non functional
 
Computer virus
Computer virusComputer virus
Computer virus
 
Autodesk maya
Autodesk mayaAutodesk maya
Autodesk maya
 

Recently uploaded

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

Access modifier and inheritance

  • 2. DEFINATION OF ACCESS MODIFIER • It is simply a keyword in java that provides accessibility of a class and its members. • Set in the access level to method, variable, classes and constructors. • Classification of access modifier are:- • Private • Protected • Public
  • 3. PRIVATE ACCESS MODIFIER • It is the most restrictive access level whereby they are accessible only within the class itself. • A superclass private members are not inherited by its subclasses. • Example of Private Access Modifier is:
  • 4.
  • 5. PROTECTED ACCESS MODIFIER • It can be accessed by only the class of same package and the subclass present in any package. • It has visibility in sub classes and Classes cannot be declared as protected. • Example of Protected Access Modifier:
  • 6.
  • 7. PUBLIC ACCESS MODIFIER • It can be access with any classes. • It is widest scope among all other modifiers. • Example of Public Access Modifier is:
  • 8.
  • 9. SCOPE OF ACCESS MODIFIERS IN TABULAR FORM Access Modifier Within Class Within Package Outside Package By Subclass only Outside Package Private Y N N N Protected Y Y Y N Public Y Y Y Y
  • 10. ACCESS MODIFIER AND INHERITANCE • Inherits features of parent’s object/class to the child’s object/class. • Extends keyword is used to inherit the features of superclass.