SlideShare a Scribd company logo
Chapter Nine Java
Inheritance
It is always nice if we could reuse something that
already exist rather than creating the same all over
again, Java supports this concept, Java classes can
be used in several ways, this is basically done by
creating new classes, reusing the properties of
existing once
Continue..
The mechanism of deriving a new class from an old
one is called inheritance, the old class is known as
the base class, superclass or parent class and the
new one is called the sub class, derived class or
child class.
To inherit a class, you simply incorporate the
definition of one class into another by using the
extends keyword.
Continue..
You can only specify one superclass for any subclass
that you create. Java does not support the
inheritance of multiple superclasses into a single
subclass. You can, as stated, create a hierarchy of
inheritance in which a subclass becomes a
superclass of another subclass. However, no class
can be a superclass of itself.
Member Access and Inheritance
Although a subclass includes all of the members of
its superclass, it cannot access those members of
the superclass that have been declared as private.
Using super to Call Superclass Constructors
A subclass can call a constructor defined by its
superclass by use of the following form of super:
super(arg-list);
Here, arg-list specifies any arguments needed by the
constructor in the superclass. super( ) must always
be the first statement executed inside a subclass’
constructor.
Continue..
The second form of super acts somewhat like this,
except that it always refers to the superclass of the
subclass in which it is used.
This usage has the following general form:
super.member
Here, member can be either a method or an
instance variable.
Continue..
This second form of super is most applicable to
situations in which member names of a subclass
hide members by the same name in the superclass.
Continue..
Note :
A Superclass Variable Can Reference a Subclass
Object
A reference variable of a superclass can be assigned
a reference to any subclass derived from that
superclass.
You will find this aspect of inheritance quite useful
in a variety of situations
Types of Inheritance
1. Single Inheritance (one super class)
2. Multiple Inheritance (Several Super classes)
3. Multi-level Inheritance (Derived from a derived
class.
4. Hierarchical Inheritance (one super class many
sub class.
Method Overriding
In a class hierarchy, when a method in a subclass
has the same name and type signature as a method
in its superclass, then the method in the subclass is
said to override the method in the superclass.
Continue..
When an overridden method is called from within
its subclass, it will always refer to the version of that
method defined by the subclass.
The version of the method defined by the
superclass will be hidden.
Abstract Class
There are situations in which you will want to define
a superclass that declares the structure of a given
abstraction without providing a complete
implementation of every method. That is,
sometimes you will want to create a superclass that
only defines a generalized form that will be shared
by all of its subclasses, leaving it to each subclass to
fill in the details.
Continue..
Such a class determines the nature of the methods
that the subclasses must implement.
You can require that certain methods be overridden
by subclasses by specifying the abstract type
modifier. These methods are sometimes referred to
as subclasser responsibility because they have no
implementation specified in the superclass.
Continue..
Thus, a subclass must override them—it cannot
simply use the version defined in the superclass.
To declare an abstract method, use this general
form:
abstract type name(parameter-list);
As you can see, no method body is present.
Any class that contains one or more abstract
methods must also be declared abstract.
Continue..
To declare a class abstract, you simply use the
abstract keyword in front of the class keyword at
the beginning of the class declaration. There can be
no objects of an abstract class. That is, an abstract
class cannot be directly instantiated with the new
operator.
Such objects would be useless, because an abstract
class is not fully defined.
Continue..
Also, you cannot declare abstract constructors, or
abstract static methods.
Any subclass of an abstract class must either
implement all of the abstract methods in the
superclass, or be declared abstract itself.
Using Final to Prevent Overriding
While method overriding is one of Java’s most
powerful features, there will be times when
you will want to prevent it from occurring.
To disallow a method from being overridden,
specify final as a modifier at the start of its
declaration. Methods declared as final cannot
be overridden.
Using Final to prevent Inheritance
Sometimes you will want to prevent a class from
being inherited. To do this, precede the class
declaration with final.
Declaring a class as final implicitly declares all of its
methods as final, too.
Thank you

More Related Content

What's hot

25 java interview questions
25 java interview questions25 java interview questions
25 java interview questions
Mehtaacademy
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
Debasish Pratihari
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#
Sireesh K
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
Tushar Desarda
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
Rai University
 
Java
JavaJava
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
Rai University
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
Week3 dq1
Week3 dq1Week3 dq1
Week3 dq1
amaxwell2012
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
Dr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java InheritanceDr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java Inheritance
jalinder123
 
Java - Inheritance Concepts
Java - Inheritance ConceptsJava - Inheritance Concepts
Java - Inheritance Concepts
Victer Paul
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
Java assignment Question
Java assignment QuestionJava assignment Question
Chapter 3i
Chapter 3iChapter 3i
Chapter 3i
siragezeynu
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Java block structure
Java block structureJava block structure
Java block structure
Ada WOU
 
C# Basics
C# BasicsC# Basics
C# Basics
Binu Bhasuran
 

What's hot (20)

25 java interview questions
25 java interview questions25 java interview questions
25 java interview questions
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
 
Java
JavaJava
Java
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Week3 dq1
Week3 dq1Week3 dq1
Week3 dq1
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Chap11
Chap11Chap11
Chap11
 
Dr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java InheritanceDr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java Inheritance
 
Java - Inheritance Concepts
Java - Inheritance ConceptsJava - Inheritance Concepts
Java - Inheritance Concepts
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Java assignment Question
Java assignment QuestionJava assignment Question
Java assignment Question
 
Chapter 3i
Chapter 3iChapter 3i
Chapter 3i
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Java block structure
Java block structureJava block structure
Java block structure
 
C# Basics
C# BasicsC# Basics
C# Basics
 

Similar to Chapter 9 java

Inheritance in java
Inheritance in javaInheritance in java
Core java by amit
Core java by amitCore java by amit
Core java by amit
Thakur Amit Tomer
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
raksharao
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
Arun Vasanth
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
Ahmad sohail Kakar
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
Nivegeetha
 
Java session2
Java session2Java session2
Java session2
Rajeev Kumar
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
Habtamu Wolde
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
OCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class DesignOCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class Design
İbrahim Kürce
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
JayMistry91473
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extraNurhanna Aziz
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Elizabeth alexander
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
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
Aravind NC
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10Terry Yoast
 

Similar to Chapter 9 java (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
Java session2
Java session2Java session2
Java session2
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
OCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class DesignOCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class Design
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extra
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
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
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 

More from Ahmad sohail Kakar

Lec 1 network types
Lec 1 network typesLec 1 network types
Lec 1 network types
Ahmad sohail Kakar
 
Lec 1 introduction
Lec 1 introductionLec 1 introduction
Lec 1 introduction
Ahmad sohail Kakar
 
Active directory restoration
Active directory restorationActive directory restoration
Active directory restoration
Ahmad sohail Kakar
 
Active directory backup
Active directory backupActive directory backup
Active directory backup
Ahmad sohail Kakar
 
Seii unit7 component-level-design
Seii unit7 component-level-designSeii unit7 component-level-design
Seii unit7 component-level-design
Ahmad sohail Kakar
 
Seii unit6 software-testing-techniques
Seii unit6 software-testing-techniquesSeii unit6 software-testing-techniques
Seii unit6 software-testing-techniques
Ahmad sohail Kakar
 
Seii unit5 ui_design
Seii unit5 ui_designSeii unit5 ui_design
Seii unit5 ui_design
Ahmad sohail Kakar
 
Seii unit4 software_process
Seii unit4 software_processSeii unit4 software_process
Seii unit4 software_process
Ahmad sohail Kakar
 
Se ii unit3-architectural-design
Se ii unit3-architectural-designSe ii unit3-architectural-design
Se ii unit3-architectural-design
Ahmad sohail Kakar
 
Se ii unit2-software_design_principles
Se ii unit2-software_design_principlesSe ii unit2-software_design_principles
Se ii unit2-software_design_principles
Ahmad sohail Kakar
 
Se ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorductionSe ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorduction
Ahmad sohail Kakar
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
Ahmad sohail Kakar
 
Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
Ahmad sohail Kakar
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
Ahmad sohail Kakar
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
Ahmad sohail Kakar
 
Chapter 3 java
Chapter 3 javaChapter 3 java
Chapter 3 java
Ahmad sohail Kakar
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
Ahmad sohail Kakar
 
Chapter 1 java
Chapter 1 java Chapter 1 java
Chapter 1 java
Ahmad sohail Kakar
 

More from Ahmad sohail Kakar (20)

Lec 1 network types
Lec 1 network typesLec 1 network types
Lec 1 network types
 
Lec 1 introduction
Lec 1 introductionLec 1 introduction
Lec 1 introduction
 
Active directory restoration
Active directory restorationActive directory restoration
Active directory restoration
 
Active directory backup
Active directory backupActive directory backup
Active directory backup
 
Seii unit7 component-level-design
Seii unit7 component-level-designSeii unit7 component-level-design
Seii unit7 component-level-design
 
Seii unit6 software-testing-techniques
Seii unit6 software-testing-techniquesSeii unit6 software-testing-techniques
Seii unit6 software-testing-techniques
 
Seii unit5 ui_design
Seii unit5 ui_designSeii unit5 ui_design
Seii unit5 ui_design
 
Seii unit4 software_process
Seii unit4 software_processSeii unit4 software_process
Seii unit4 software_process
 
Se ii unit3-architectural-design
Se ii unit3-architectural-designSe ii unit3-architectural-design
Se ii unit3-architectural-design
 
Se ii unit2-software_design_principles
Se ii unit2-software_design_principlesSe ii unit2-software_design_principles
Se ii unit2-software_design_principles
 
Se ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorductionSe ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorduction
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
 
Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
 
Chapter 3 java
Chapter 3 javaChapter 3 java
Chapter 3 java
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Chapter 1 java
Chapter 1 java Chapter 1 java
Chapter 1 java
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

Chapter 9 java

  • 2. Inheritance It is always nice if we could reuse something that already exist rather than creating the same all over again, Java supports this concept, Java classes can be used in several ways, this is basically done by creating new classes, reusing the properties of existing once
  • 3. Continue.. The mechanism of deriving a new class from an old one is called inheritance, the old class is known as the base class, superclass or parent class and the new one is called the sub class, derived class or child class. To inherit a class, you simply incorporate the definition of one class into another by using the extends keyword.
  • 4. Continue.. You can only specify one superclass for any subclass that you create. Java does not support the inheritance of multiple superclasses into a single subclass. You can, as stated, create a hierarchy of inheritance in which a subclass becomes a superclass of another subclass. However, no class can be a superclass of itself.
  • 5. Member Access and Inheritance Although a subclass includes all of the members of its superclass, it cannot access those members of the superclass that have been declared as private.
  • 6. Using super to Call Superclass Constructors A subclass can call a constructor defined by its superclass by use of the following form of super: super(arg-list); Here, arg-list specifies any arguments needed by the constructor in the superclass. super( ) must always be the first statement executed inside a subclass’ constructor.
  • 7. Continue.. The second form of super acts somewhat like this, except that it always refers to the superclass of the subclass in which it is used. This usage has the following general form: super.member Here, member can be either a method or an instance variable.
  • 8. Continue.. This second form of super is most applicable to situations in which member names of a subclass hide members by the same name in the superclass.
  • 9. Continue.. Note : A Superclass Variable Can Reference a Subclass Object A reference variable of a superclass can be assigned a reference to any subclass derived from that superclass. You will find this aspect of inheritance quite useful in a variety of situations
  • 10. Types of Inheritance 1. Single Inheritance (one super class) 2. Multiple Inheritance (Several Super classes) 3. Multi-level Inheritance (Derived from a derived class. 4. Hierarchical Inheritance (one super class many sub class.
  • 11. Method Overriding In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.
  • 12. Continue.. When an overridden method is called from within its subclass, it will always refer to the version of that method defined by the subclass. The version of the method defined by the superclass will be hidden.
  • 13. Abstract Class There are situations in which you will want to define a superclass that declares the structure of a given abstraction without providing a complete implementation of every method. That is, sometimes you will want to create a superclass that only defines a generalized form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details.
  • 14. Continue.. Such a class determines the nature of the methods that the subclasses must implement. You can require that certain methods be overridden by subclasses by specifying the abstract type modifier. These methods are sometimes referred to as subclasser responsibility because they have no implementation specified in the superclass.
  • 15. Continue.. Thus, a subclass must override them—it cannot simply use the version defined in the superclass. To declare an abstract method, use this general form: abstract type name(parameter-list); As you can see, no method body is present. Any class that contains one or more abstract methods must also be declared abstract.
  • 16. Continue.. To declare a class abstract, you simply use the abstract keyword in front of the class keyword at the beginning of the class declaration. There can be no objects of an abstract class. That is, an abstract class cannot be directly instantiated with the new operator. Such objects would be useless, because an abstract class is not fully defined.
  • 17. Continue.. Also, you cannot declare abstract constructors, or abstract static methods. Any subclass of an abstract class must either implement all of the abstract methods in the superclass, or be declared abstract itself.
  • 18. Using Final to Prevent Overriding While method overriding is one of Java’s most powerful features, there will be times when you will want to prevent it from occurring. To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden.
  • 19. Using Final to prevent Inheritance Sometimes you will want to prevent a class from being inherited. To do this, precede the class declaration with final. Declaring a class as final implicitly declares all of its methods as final, too.