SlideShare a Scribd company logo
Types of inheritance in java
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
Introduction
 On the basis of class, there can be three types of
inheritance in java: single, multilevel and hierarchical.
 In java programming, multiple and hybrid inheritance
is supported through interface only.
Types of Inheritance
Cont..
Single Inheritance Example
 class Animal{
 void eat(){System.out.println("eating...");}
 }
 class Dog extends Animal{
 void bark(){System.out.println("barking...");}
 }
 class TestInheritance{
 public static void main(String args[]){
 Dog d=new Dog();
 d.bark();
 d.eat();
 }}
Multilevel Inheritance Example
 class Animal{
 void eat(){System.out.println("eating...");}
 }
 class Dog extends Animal{
 void bark(){System.out.println("barking...");}
 }
 class BabyDog extends Dog{
 void weep(){System.out.println("weeping...");}
 }
 class TestInheritance2{
 public static void main(String args[]){
 BabyDog d=new BabyDog();
 d.weep();
 d.bark();
 d.eat();
 }}
Hierarchical Inheritance Example
 class Animal{
 void eat(){System.out.println("eating...");}
 }
 class Dog extends Animal{
 void bark(){System.out.println("barking...");}
 }
 class Cat extends Animal{
 void meow(){System.out.println("meowing...");}
 }
 class TestInheritance3{
 public static void main(String args[]){
 Cat c=new Cat();
 c.meow();
 c.eat();
 }}
Assignment
 Explain Types of Inheritance in java with example.

More Related Content

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 

What's hot (20)

Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
some basic knowledge about Java programming
some basic knowledge about Java programming some basic knowledge about Java programming
some basic knowledge about Java programming
 
javainheritance
javainheritancejavainheritance
javainheritance
 
OOP Basic Concepts
OOP Basic ConceptsOOP Basic Concepts
OOP Basic Concepts
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
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
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Dr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java InheritanceDr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java Inheritance
 
OOPs Lecture 2
OOPs Lecture 2OOPs Lecture 2
OOPs Lecture 2
 
Pi j4.1 packages
Pi j4.1 packagesPi j4.1 packages
Pi j4.1 packages
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 

Similar to Types of inheritance in java

About java
About javaAbout java
About java
Jay Xu
 
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptxhhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
ZeelGoyani
 
Interfaces & Abstract Classes
Interfaces & Abstract ClassesInterfaces & Abstract Classes
Interfaces & Abstract Classes
Bharat17485
 
Java class 3
Java class 3Java class 3
Java class 3
Edureka!
 

Similar to Types of inheritance in java (20)

inheritance
inheritanceinheritance
inheritance
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
Inheritance & polymorphism java oop
Inheritance & polymorphism java oopInheritance & polymorphism java oop
Inheritance & polymorphism java oop
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
 
About java
About javaAbout java
About java
 
inheritance.pptx
inheritance.pptxinheritance.pptx
inheritance.pptx
 
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptxhhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
hhuhuihuhuihPresentations_PPT_Unit-5_OOP.pptx
 
Unit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptxUnit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptx
 
Day_2.1.pptx
Day_2.1.pptxDay_2.1.pptx
Day_2.1.pptx
 
Interfaces & Abstract Classes
Interfaces & Abstract ClassesInterfaces & Abstract Classes
Interfaces & Abstract Classes
 
Java class 3
Java class 3Java class 3
Java class 3
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Dive into Object Orienter Programming and Design Patterns through java
Dive into Object Orienter Programming and Design Patterns through javaDive into Object Orienter Programming and Design Patterns through java
Dive into Object Orienter Programming and Design Patterns through java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 

More from chauhankapil

Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
chauhankapil
 

More from chauhankapil (20)

Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Request
 
Jsp server response
Jsp   server responseJsp   server response
Jsp server response
 
Markov decision process
Markov decision processMarkov decision process
Markov decision process
 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learning
 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)
 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interference
 
Jsp
JspJsp
Jsp
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistion
 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based system
 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logics
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 

Recently uploaded (20)

Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptx
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 

Types of inheritance in java

  • 1. Types of inheritance in java Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. Introduction  On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical.  In java programming, multiple and hybrid inheritance is supported through interface only.
  • 5. Single Inheritance Example  class Animal{  void eat(){System.out.println("eating...");}  }  class Dog extends Animal{  void bark(){System.out.println("barking...");}  }  class TestInheritance{  public static void main(String args[]){  Dog d=new Dog();  d.bark();  d.eat();  }}
  • 6. Multilevel Inheritance Example  class Animal{  void eat(){System.out.println("eating...");}  }  class Dog extends Animal{  void bark(){System.out.println("barking...");}  }  class BabyDog extends Dog{  void weep(){System.out.println("weeping...");}  }  class TestInheritance2{  public static void main(String args[]){  BabyDog d=new BabyDog();  d.weep();  d.bark();  d.eat();  }}
  • 7. Hierarchical Inheritance Example  class Animal{  void eat(){System.out.println("eating...");}  }  class Dog extends Animal{  void bark(){System.out.println("barking...");}  }  class Cat extends Animal{  void meow(){System.out.println("meowing...");}  }  class TestInheritance3{  public static void main(String args[]){  Cat c=new Cat();  c.meow();  c.eat();  }}
  • 8. Assignment  Explain Types of Inheritance in java with example.