SlideShare a Scribd company logo
1 of 11
How do I use inheritance in Java?
Index
What is Java inheritance
Example of Java inheritance
Keywords Extends
Prepared By
Preeti
Java class supports reuse through inheritance and composition. This
two-part tutorial shows you how to use inheritance in your Java
programs. In Part 1, Learn how to use the extends keyword to derive a
child from a parent class. In part 2 you will visit java.long.Object, this is
the superclass of Java, from which any other class inherits.
All freshers who willing to make career in java ,Java certification
course is a essential to all freshers.
To complete your knowledge about inheritance, check my Java tip, if
you want to use composition vs inheritance.
Learn why composition is an important addition to inheritance and how
to use it to avoid encapsulation problems in your Java programs.
To complete your knowledge about inheritance, check my Java tip, if
you want to use composition vs inheritance.
Learn why composition is an important addition to inheritance and how
to use it to avoid encapsulation problems in your Java programs.
Java Inheritance: Two Examples
Inheritance is a programming construct that software developers use to
create is-a relationships between categories.
By inheritance, we can derive more specific categories from more
generic ones. The more specific category is a type of generic category.
For example, a current account is a type of account where you can
deposit and withdraw funds.
Similarly, a truck is a kind of vehicle for towing large objects.
Inheritance can descend through multiple levels, leading to more and
more specific categories.
As an example, figure shows the number 1 car and truck inherit from
vehicle; Combi inherit from car, and garbage truck inherit from truck.
Arrows show from more specific "child" categories (below) to less
specific "parents"categories (above).
Figure 1. A few inheritance hierarchies are rooted in the common
vehicle category
This example demonstrates single inheritance in which a child category
inherits state and behavior from an immediate parent category.
In contrast, multiple inheritance a child category to inherit state and
behavior from two or more parent categories.
The hierarchy in Figure 2 illustrates the Multiple Inheritance.
https://www.exltech.in/java-training.html
Figure 2.
Hovercraft multiply inherits from land vehicle and watercraft categories
Categories are described by classes.
Java supports single inheritance through class extension, in which a
class inherits directly accessible fields and methods from another class
by extending this class. However,
Java does
When you view an inheritance hierarchy, you can easily detect multiple
inherits by the presence of a diamond pattern.
Figure 2 shows this pattern in the context of vehicle, land vehicle,
watercraft and hovercraft.
The keyword extends
Java supports the class extension using the extends keyword. If present,
extends specifies a parent-child relationship between two classes.
Below I use extended to a relationship between the classes vehicle and
car, and then between Account and SavingsAccount:
Exltech is offering Practical Java course training in Pune with hands on
experienced in coding.
Vist us to know more details about Java course
https://www.exltech.in/

More Related Content

Similar to How do i use inheritance in java?

Java presention Inheritance present By Showrov Ahamed
Java presention Inheritance present By Showrov AhamedJava presention Inheritance present By Showrov Ahamed
Java presention Inheritance present By Showrov AhamedMd Showrov Ahmed
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with javaAAKANKSHA JAIN
 
159747608 a-training-report-on
159747608 a-training-report-on159747608 a-training-report-on
159747608 a-training-report-onhomeworkping7
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxRkGupta83
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxnaeemcse
 
Inheritance and its necessity in java.ppt
Inheritance and its necessity in java.pptInheritance and its necessity in java.ppt
Inheritance and its necessity in java.pptssuserf170c4
 
INHERTANCE , NARROW AND WIDENING
INHERTANCE , NARROW AND WIDENING INHERTANCE , NARROW AND WIDENING
INHERTANCE , NARROW AND WIDENING ManpreetSingh1387
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxkristinatemen
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
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
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7dplunkett
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questionsnishajj
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questionsnishajj
 

Similar to How do i use inheritance in java? (20)

Java presention Inheritance present By Showrov Ahamed
Java presention Inheritance present By Showrov AhamedJava presention Inheritance present By Showrov Ahamed
Java presention Inheritance present By Showrov Ahamed
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
159747608 a-training-report-on
159747608 a-training-report-on159747608 a-training-report-on
159747608 a-training-report-on
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptx
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
Inheritance and its necessity in java.ppt
Inheritance and its necessity in java.pptInheritance and its necessity in java.ppt
Inheritance and its necessity in java.ppt
 
INHERTANCE , NARROW AND WIDENING
INHERTANCE , NARROW AND WIDENING INHERTANCE , NARROW AND WIDENING
INHERTANCE , NARROW AND WIDENING
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
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
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Chapter 3i
Chapter 3iChapter 3i
Chapter 3i
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
 
Top 10 java oops interview questions
Top 10 java oops interview questionsTop 10 java oops interview questions
Top 10 java oops interview questions
 

More from kritikumar16

How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...kritikumar16
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java kritikumar16
 
5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.kritikumar16
 
How do i use inheritance in java?
How do i use inheritance in java?How do i use inheritance in java?
How do i use inheritance in java?kritikumar16
 
How do i use inheritance in java?
How do i use inheritance in java?How do i use inheritance in java?
How do i use inheritance in java?kritikumar16
 
List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019  List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019 kritikumar16
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?kritikumar16
 
How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...kritikumar16
 
List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019  List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019 kritikumar16
 
Introduction to advanced java
Introduction to advanced javaIntroduction to advanced java
Introduction to advanced javakritikumar16
 

More from kritikumar16 (10)

How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java
 
5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.5 things about introduction to advanced java you have to experience it yourself.
5 things about introduction to advanced java you have to experience it yourself.
 
How do i use inheritance in java?
How do i use inheritance in java?How do i use inheritance in java?
How do i use inheritance in java?
 
How do i use inheritance in java?
How do i use inheritance in java?How do i use inheritance in java?
How do i use inheritance in java?
 
List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019  List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?
 
How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...
 
List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019  List of 7 popular java frameworks for 2019
List of 7 popular java frameworks for 2019
 
Introduction to advanced java
Introduction to advanced javaIntroduction to advanced java
Introduction to advanced java
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
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
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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
 
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
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

How do i use inheritance in java?

  • 1. How do I use inheritance in Java?
  • 2. Index What is Java inheritance Example of Java inheritance Keywords Extends
  • 4. Java class supports reuse through inheritance and composition. This two-part tutorial shows you how to use inheritance in your Java programs. In Part 1, Learn how to use the extends keyword to derive a child from a parent class. In part 2 you will visit java.long.Object, this is the superclass of Java, from which any other class inherits. All freshers who willing to make career in java ,Java certification course is a essential to all freshers. To complete your knowledge about inheritance, check my Java tip, if you want to use composition vs inheritance. Learn why composition is an important addition to inheritance and how to use it to avoid encapsulation problems in your Java programs.
  • 5. To complete your knowledge about inheritance, check my Java tip, if you want to use composition vs inheritance. Learn why composition is an important addition to inheritance and how to use it to avoid encapsulation problems in your Java programs. Java Inheritance: Two Examples Inheritance is a programming construct that software developers use to create is-a relationships between categories. By inheritance, we can derive more specific categories from more generic ones. The more specific category is a type of generic category. For example, a current account is a type of account where you can deposit and withdraw funds. Similarly, a truck is a kind of vehicle for towing large objects.
  • 6. Inheritance can descend through multiple levels, leading to more and more specific categories. As an example, figure shows the number 1 car and truck inherit from vehicle; Combi inherit from car, and garbage truck inherit from truck. Arrows show from more specific "child" categories (below) to less specific "parents"categories (above). Figure 1. A few inheritance hierarchies are rooted in the common vehicle category This example demonstrates single inheritance in which a child category inherits state and behavior from an immediate parent category.
  • 7. In contrast, multiple inheritance a child category to inherit state and behavior from two or more parent categories. The hierarchy in Figure 2 illustrates the Multiple Inheritance.
  • 8. https://www.exltech.in/java-training.html Figure 2. Hovercraft multiply inherits from land vehicle and watercraft categories Categories are described by classes. Java supports single inheritance through class extension, in which a class inherits directly accessible fields and methods from another class by extending this class. However, Java does
  • 9. When you view an inheritance hierarchy, you can easily detect multiple inherits by the presence of a diamond pattern. Figure 2 shows this pattern in the context of vehicle, land vehicle, watercraft and hovercraft.
  • 10. The keyword extends Java supports the class extension using the extends keyword. If present, extends specifies a parent-child relationship between two classes. Below I use extended to a relationship between the classes vehicle and car, and then between Account and SavingsAccount:
  • 11. Exltech is offering Practical Java course training in Pune with hands on experienced in coding. Vist us to know more details about Java course https://www.exltech.in/