SlideShare a Scribd company logo
1 of 20
Inheritance
Presented by:-
Disha Singh
Contents
 Introduction of inheritance
 Classes classification
Super class
Intermediate class
Child class
 Types of inheritance
Single inheritance
Multilevel inheritance
Hierarchical inheritance
 Interface
 Abstract class
 Method overriding
Inheritance
• One of the most effective features of Object-
oriented programming.
• It is the capability of one class to inherit
properties from another class.
• Establish a link/connectivity between 2 or
more classes.
• Permits sharing and accessing properties
from one to another class.
• To establish this relation java uses “extends”
keyword.
• Represents “IS-A” relationship.
Real world example:-
Category of classes on the basic of
inheritance
Super class
(base/parent/driver/inheritance class).
Intermediate class
(mediating/dual class).
Child class
(sub/associate/derived/inherited class).
1. Super class
 Top located class
 Service provider
(its properties accessed by all its lower level
class).
2. Intermediate class
 Middle located class
 Having dual policy
(obtain properties of upper class and transmit
properties to lower level class)
3. Child class
 Bottom located class
 Much benefitted class
 Much loaded class
(properties of child class as well as class and
parent class can be accessed by only the object of child class)
class A Parent
class
{
............
............
}
class B
Intermediate
{ class
...........
...........
}
class C
{
...........
...........
}
Child
class
Types of inheritance
 Single inheritance
 Multilevel inheritance
 Hierarchical inheritance
Single inheritance
 A structure having one and only one parent as well as child
class.
 Child class is authorized to access the property of parent
class.
Syntax:-
class A
{
..............
..............
}
class B extends A
{
.............
.............
}
Parent
class
Child
class
Sharing
of
property
Multilevel inheritance
 When a class extends a class, which extends another class then
this is called as multilevel inheritance.
 Child class as well as intermediate class may access the properties
of upper level classes. Syntax:-
class A
{
..............
..............
}
class B extends A
{
.............
.............
}
class C extends B
{
..............
..............
}
Parent class
Intermediate
class
Child class
Example:-
Hierarchical inheritance
 When more than one classes are derived from a single base class,
such type of inheritance is called as hierarchical inheritance.
 Child classes must be connected with
only parent class.
Syntax:-
class A
{
..............
..............
}
class B extends A
{
.............
.............
}
class C extends A
{
..............
..............
}
Parent
class
child class
child class
Example:-
Interface
 Java supports a special feature called
interface.
 This feature helps to connect a class with
more than one classes
 For this type of connectivity
java uses “implements” keyword.
 Object of interface cannot be created.
Syntax:-
interface A {
..............
..............
}
interface B
{
.............
.............
}
class C implements A
{
..............
..............
}
class D implements A
{
..........
..........
}
interface
Child class
Intermediate
class
interface
Intermediate
class
Abstract class
 A class that is declared with “abstract” keyword, is
known as abstract class in java.
 It can have abstract and non abstract methods(method
with body).
 No object of abstract class can be created.
 Abstract class can contain constructor and instance
variable.
 It contain a class with 0 to 100% abstraction.
 Constructor chaining can be done in abstract class.
 Syntax:
abstract class<class-name>{ }
//an abstract class without any abstract method
Abstract class Base
{
void fun()
{
system.out.println(“base fun() called”);
}
}
class Derived extends Base
{
}
class Main
{
public static void main(String args [])
{
Derived d= new Derived();
d.fun();
}
}
Difference between abstract
class &interface
Abstract class Interface
•It provides 0 to 100% abstraction
of methods.
It provides 100% abstraction of
methods.
•A class can inherit only one
abstract class at a time ( no
multiple inheritance).
A class can inherit many interface
at a time .
•Abstract class contain constructor
and instance variable.
Interface do not contain constructor
and instance variable.
•Constructor chaining will be done
in abstract class .
No constructor chaining will be
possible.
Method Overriding
 If the subclass(child class) has the same
method as declared in the parent class, it
is called method overriding
 Rules for method overriding in java
Method must have same name as in the
parent
class.
Method must have same parameter as in the
parent class.
Must be IS-A relationship(inheritance).
Example:-
class Human
{
//overridden method
public void eat()
{
System.out.println(“human is eating”);
}
}
class Boy extends Human
{
//overriding method
public void eat()
{
System.out.println(“Boy is eating”);
}
public static void main(String args[])
{
Boy obj=new Boy();
//this will call the child class version of eat()
obj.eat();
}
}
Thank you

More Related Content

What's hot (20)

Inheritance
InheritanceInheritance
Inheritance
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance in c++ part1
Inheritance in c++ part1Inheritance in c++ part1
Inheritance in c++ part1
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In Java
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)
 
Inheritance
InheritanceInheritance
Inheritance
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 

Similar to Everything You Need to Know About Inheritance in Java

Similar to Everything You Need to Know About Inheritance in Java (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-i
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
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)
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Java
JavaJava
Java
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptx
 

Recently uploaded

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
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
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
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
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
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
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
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Everything You Need to Know About Inheritance in Java

  • 2. Contents  Introduction of inheritance  Classes classification Super class Intermediate class Child class  Types of inheritance Single inheritance Multilevel inheritance Hierarchical inheritance  Interface  Abstract class  Method overriding
  • 3. Inheritance • One of the most effective features of Object- oriented programming. • It is the capability of one class to inherit properties from another class. • Establish a link/connectivity between 2 or more classes. • Permits sharing and accessing properties from one to another class. • To establish this relation java uses “extends” keyword. • Represents “IS-A” relationship.
  • 5. Category of classes on the basic of inheritance Super class (base/parent/driver/inheritance class). Intermediate class (mediating/dual class). Child class (sub/associate/derived/inherited class).
  • 6. 1. Super class  Top located class  Service provider (its properties accessed by all its lower level class). 2. Intermediate class  Middle located class  Having dual policy (obtain properties of upper class and transmit properties to lower level class) 3. Child class  Bottom located class  Much benefitted class  Much loaded class (properties of child class as well as class and parent class can be accessed by only the object of child class) class A Parent class { ............ ............ } class B Intermediate { class ........... ........... } class C { ........... ........... } Child class
  • 7. Types of inheritance  Single inheritance  Multilevel inheritance  Hierarchical inheritance
  • 8. Single inheritance  A structure having one and only one parent as well as child class.  Child class is authorized to access the property of parent class. Syntax:- class A { .............. .............. } class B extends A { ............. ............. } Parent class Child class Sharing of property
  • 9. Multilevel inheritance  When a class extends a class, which extends another class then this is called as multilevel inheritance.  Child class as well as intermediate class may access the properties of upper level classes. Syntax:- class A { .............. .............. } class B extends A { ............. ............. } class C extends B { .............. .............. } Parent class Intermediate class Child class
  • 11. Hierarchical inheritance  When more than one classes are derived from a single base class, such type of inheritance is called as hierarchical inheritance.  Child classes must be connected with only parent class. Syntax:- class A { .............. .............. } class B extends A { ............. ............. } class C extends A { .............. .............. } Parent class child class child class
  • 13. Interface  Java supports a special feature called interface.  This feature helps to connect a class with more than one classes  For this type of connectivity java uses “implements” keyword.  Object of interface cannot be created. Syntax:- interface A { .............. .............. } interface B { ............. ............. } class C implements A { .............. .............. } class D implements A { .......... .......... } interface Child class Intermediate class interface Intermediate class
  • 14. Abstract class  A class that is declared with “abstract” keyword, is known as abstract class in java.  It can have abstract and non abstract methods(method with body).  No object of abstract class can be created.  Abstract class can contain constructor and instance variable.  It contain a class with 0 to 100% abstraction.  Constructor chaining can be done in abstract class.  Syntax: abstract class<class-name>{ }
  • 15. //an abstract class without any abstract method Abstract class Base { void fun() { system.out.println(“base fun() called”); } } class Derived extends Base { } class Main { public static void main(String args []) { Derived d= new Derived(); d.fun(); } }
  • 16. Difference between abstract class &interface Abstract class Interface •It provides 0 to 100% abstraction of methods. It provides 100% abstraction of methods. •A class can inherit only one abstract class at a time ( no multiple inheritance). A class can inherit many interface at a time . •Abstract class contain constructor and instance variable. Interface do not contain constructor and instance variable. •Constructor chaining will be done in abstract class . No constructor chaining will be possible.
  • 17. Method Overriding  If the subclass(child class) has the same method as declared in the parent class, it is called method overriding  Rules for method overriding in java Method must have same name as in the parent class. Method must have same parameter as in the parent class. Must be IS-A relationship(inheritance).
  • 19. class Human { //overridden method public void eat() { System.out.println(“human is eating”); } } class Boy extends Human { //overriding method public void eat() { System.out.println(“Boy is eating”); } public static void main(String args[]) { Boy obj=new Boy(); //this will call the child class version of eat() obj.eat(); } }