SlideShare a Scribd company logo
1 of 27
SEMINAR ON JAVA
INHERITANCE
THE MECHANISM
OF DERIVING A NEW
CLASS FROM AN OLD
ONE IS CALLED
INHERITANCE.
•THE OLD CLASS IS KNOWN
AS BASE CLASS OR SUPER
CLASS OR PARENT CLASS

THE NEW ONE IS CALLED
THE SUB CLASS OR DERIVED
CLASS OR CHILD CLASS
TYPES OF INHARITANCE
SINGLE INHERITANCE
         •ONLY
          ONE BASE
          CLASS
MULTILEVEL
        INHERITANCE
GRAND FATHER   SUPER CLASS


FATHER         INTERMEDIATE SUPERCLASS



CHILD          SUB CLASS
A DERIVED CLASS WITH MULTILEVEL BASE CLASSES IS DECLARED AS
FOLLOWS
CLASS A
{
…………
…………
}
CLASS B extends A // first level
{
………….
………….
}
CLASS C //second level
{
………….
………….
}
EXAMPLE
HERE CERTAIN
FEATURES OF ONE
LEVEL ARE SHARED
BY MANY OTHER
BELOW THE LEVEL.
MULTIPLE INHERITANCE
   OVERRIDING CAN BE DONE BY
    DEFINING A METHOD IN THE SUB
    CLASS THAT HAS THE SAME
    NAME,SAME ARGUMENTS AND
    SAME RETURN TYPE AS A
    METHOD IN THE SUPER CLASS.

   THIS IS KNOWN AS OVERRIDING.
FINALIZER METHODS
 FINILIZATION IS JUST OPPOSITE TO
 INITIALASATION.
 JAVA RUN-TIME IS AN AUTOMATIC
  GARBAGE COLLECTING SYSTEM.
 IT FREES THE MEMORY RESOURCES USED
  BY OBJECTS.
 BUT OBJECTS MAY HOLD OTHER NON-
  OBJECT RESOURCES SUCH AS FILE
  DESCRIPTORS OR WINDOW SYSTEM
  FONTS.
 THE GARBAGE COLLECTOR CANNOT FREE
  THESE RESOURCES.
 IN ORDER TO FREE THIS WE USE FINALIZER
  METHOD.
 THIS IS SIMILAR TO

 DESTRUCTORS.
 THE FINALIZER METHOD IS SIMPLY

 FINALIZE()
ABSTRACT METHODS
 FINALIZER
          HELPS US NOT TO RE-
 DEFINE THE METHOD IN SUB
 CLASS.

 BUT
    TO DO THE OPPOSITE, i.e.
 REDEFINE THE METHOD IN SUB
 CLASS,WE USE THE MODIFIER
 KEYWORD abstract IN THE
 METHOD DEFINITION
EXAMPLE

abstract class shape
{
………….
………….
abstract void draw();
………….
………….
}
VISIBILITY CONTROL
 IT
   IS ALSO KNOWN AS ACCESS
 MODIFIERS.THIS PROVIDES THREE
 TYPES OF MODIFIERS:

PUBLIC

PRIVATE

PROTECTED
By   simply declaring the variable or
 method as public it is visible to
 entire class in which it is defined.

A variable or method which is
 declared as public has the widest
 possible visibility and
 accessible everywhere.
FRIENDLY ACCESS
• When no access modifier is specified,the
  member defaults to a limited version of public
  accessibility known as “friendly” level of
  access.

• this makes fields visible only in the same
  package,but not in other packages.
   The visibility lies in between the public
    access and friendly access.

   The protected modifier makes the fields
    visible not only to all classes and sub
    classes in the same package but also to
    sub classes in other packages.
PRIVATE ACCESS
 They enjoy the highest   degree of protection.
 They are accessible only with their own class.
 They cannot      be accessed and inherited
 by sub classes.
 The method declared as private behaves like a
  method declared as final.
 It prevents the method from being sub classed.
A  field can be declared with two key
  words private and protected together like:
Private protected int codenumber;
 the visibility level is between the
  “protected” access and private access.
 This makes the fields visible in all
  subclasses regardless of what package
  they are in
   USE PUBLIC IF THE FIELD IS TO BE VISIBLE
    EVERYWHERE.
   USE PROTECTED IF THE FIELD IS TO BE
    VISIBLE EVERYWHERE IN THE CURRENT
    PACKAGE AND ALSO SUBCLASSES IN
    OTHER PACKAGES.
   USE “DEFAULT” IF THE FIELD IS TO BE
    VISIBLE EVERYWHERE IN THE CURRENT
    PACKAGE ONLY.
   USE PRIVATE PROTECTED IF THE FIELD IS
thank you

More Related Content

What's hot

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaRahulAnanda1
 
Java package
Java packageJava package
Java packageCS_GDRCST
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In JavaMD SALEEM QAISAR
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 

What's hot (20)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Interface in java
Interface in javaInterface in java
Interface in java
 
History of java'
History of java'History of java'
History of java'
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java package
Java packageJava package
Java package
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In Java
 
Inheritance
InheritanceInheritance
Inheritance
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Java interface
Java interfaceJava interface
Java interface
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
OOP java
OOP javaOOP java
OOP java
 

Viewers also liked

Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core javamahir jain
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
Java Presentation
Java PresentationJava Presentation
Java Presentationaitrichtech
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ? SoonTips.com
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentationsameerraaj
 

Viewers also liked (20)

Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java basic
Java basicJava basic
Java basic
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ?
 
Android seminar ppt
Android seminar pptAndroid seminar ppt
Android seminar ppt
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
 
Networking ppt
Networking ppt Networking ppt
Networking ppt
 

Similar to Seminar on java (20)

Chapter 3i
Chapter 3iChapter 3i
Chapter 3i
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
INHERITANCE
INHERITANCEINHERITANCE
INHERITANCE
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Oops
OopsOops
Oops
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
Presentation 3.pdf
Presentation 3.pdfPresentation 3.pdf
Presentation 3.pdf
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Seminar on java

  • 3. THE MECHANISM OF DERIVING A NEW CLASS FROM AN OLD ONE IS CALLED INHERITANCE.
  • 4. •THE OLD CLASS IS KNOWN AS BASE CLASS OR SUPER CLASS OR PARENT CLASS THE NEW ONE IS CALLED THE SUB CLASS OR DERIVED CLASS OR CHILD CLASS
  • 6. SINGLE INHERITANCE •ONLY ONE BASE CLASS
  • 7. MULTILEVEL INHERITANCE GRAND FATHER SUPER CLASS FATHER INTERMEDIATE SUPERCLASS CHILD SUB CLASS
  • 8. A DERIVED CLASS WITH MULTILEVEL BASE CLASSES IS DECLARED AS FOLLOWS CLASS A { ………… ………… } CLASS B extends A // first level { …………. …………. } CLASS C //second level { …………. …………. }
  • 9.
  • 11. HERE CERTAIN FEATURES OF ONE LEVEL ARE SHARED BY MANY OTHER BELOW THE LEVEL.
  • 13. OVERRIDING CAN BE DONE BY DEFINING A METHOD IN THE SUB CLASS THAT HAS THE SAME NAME,SAME ARGUMENTS AND SAME RETURN TYPE AS A METHOD IN THE SUPER CLASS.  THIS IS KNOWN AS OVERRIDING.
  • 14. FINALIZER METHODS  FINILIZATION IS JUST OPPOSITE TO INITIALASATION.  JAVA RUN-TIME IS AN AUTOMATIC GARBAGE COLLECTING SYSTEM.  IT FREES THE MEMORY RESOURCES USED BY OBJECTS.  BUT OBJECTS MAY HOLD OTHER NON- OBJECT RESOURCES SUCH AS FILE DESCRIPTORS OR WINDOW SYSTEM FONTS.
  • 15.  THE GARBAGE COLLECTOR CANNOT FREE THESE RESOURCES.  IN ORDER TO FREE THIS WE USE FINALIZER METHOD.  THIS IS SIMILAR TO DESTRUCTORS.  THE FINALIZER METHOD IS SIMPLY FINALIZE()
  • 16. ABSTRACT METHODS  FINALIZER HELPS US NOT TO RE- DEFINE THE METHOD IN SUB CLASS.  BUT TO DO THE OPPOSITE, i.e. REDEFINE THE METHOD IN SUB CLASS,WE USE THE MODIFIER KEYWORD abstract IN THE METHOD DEFINITION
  • 17. EXAMPLE abstract class shape { …………. …………. abstract void draw(); …………. …………. }
  • 18. VISIBILITY CONTROL  IT IS ALSO KNOWN AS ACCESS MODIFIERS.THIS PROVIDES THREE TYPES OF MODIFIERS: PUBLIC PRIVATE PROTECTED
  • 19. By simply declaring the variable or method as public it is visible to entire class in which it is defined. A variable or method which is declared as public has the widest possible visibility and accessible everywhere.
  • 20.
  • 21. FRIENDLY ACCESS • When no access modifier is specified,the member defaults to a limited version of public accessibility known as “friendly” level of access. • this makes fields visible only in the same package,but not in other packages.
  • 22. The visibility lies in between the public access and friendly access.  The protected modifier makes the fields visible not only to all classes and sub classes in the same package but also to sub classes in other packages.
  • 23. PRIVATE ACCESS  They enjoy the highest degree of protection.  They are accessible only with their own class.  They cannot be accessed and inherited by sub classes.  The method declared as private behaves like a method declared as final.  It prevents the method from being sub classed.
  • 24. A field can be declared with two key words private and protected together like: Private protected int codenumber;  the visibility level is between the “protected” access and private access.  This makes the fields visible in all subclasses regardless of what package they are in
  • 25. USE PUBLIC IF THE FIELD IS TO BE VISIBLE EVERYWHERE.  USE PROTECTED IF THE FIELD IS TO BE VISIBLE EVERYWHERE IN THE CURRENT PACKAGE AND ALSO SUBCLASSES IN OTHER PACKAGES.  USE “DEFAULT” IF THE FIELD IS TO BE VISIBLE EVERYWHERE IN THE CURRENT PACKAGE ONLY.  USE PRIVATE PROTECTED IF THE FIELD IS
  • 26.