SlideShare uma empresa Scribd logo
TOPIC – MULTIPLE
INHERITANCE THROUGH
INTERFACES
PREPARED BY –
NAME - PINKI KUMARI
ROLL NO. - CSC/21/25
INHERITANCE
• INHERITANCE – Inheritance is inheriting the
properties of one class(Parent class) in the another
class(child class). This relation can be defined by
using the extends keyword as −
public class childClass extends Parentclass{
}
• Java is an Object Oriented Programming
language and supports the feature of inheritance.
We cannot have Multiple Inheritance in Java
directly ,but it can be implemented using Interfaces.
• The class which inherits the properties is known as sub class or child class and the class whose
properties are inherited is super class or parent class. In inheritance a copy of parent class members
is created in the child class object. Therefore, using the child class object you can access the members
of the both classes . The various types of inheritance in java are :-
• Single
• Multilevel
• hierarchical
• Multiple
• Hybrid
Multiple inheritance is inheriting properties of two or more parent classes to one
child class . As given in the below diagram class A and class B is being inherited by
the child class C
CLASS A
CLASS B
CLASS C
Sample code of how multiple inheritance works in java is given below. First two classes are
made ParentA and ParentB and they both have same signature methods walk() . a child class is made which is
inheriting both the classes by using a keyword 'extends'
OUTPUT :
• In the above code the compiler will get confuse which method to call when object of child class calls
walk() method and results in compile time error.
• The solution to this problem of Multiple inheritance is using Interface
INTERFACE IN JAVA
Interface is a collection of abstract methods(non-defined methods). A class implements an interface, hence
inheriting the abstract methods of the interface. An interface may also contain constants, Variables,
default methods, static blocks, methods etc . Interfaces are public ,static and final.
The syntax of interface is given below :-
To inherit a class in another class we use the keyword extends,
And to inherit or to implement a interface in class we use implements
keyword.
CLASS
CLASS
INTERFACE
CLASS
EXTENDS IMPLEMENTS
• BELOW IS AN EXAMPLE OF WHERE MULTIPLE INHERITANCE IS ACHIEVED WITH THE HELP OF
INTERFACES.
OUTPUT :-
• hence, in the above code we have achieved Multiple inheritance in java with the help of interfaces where we have declared
our methods in the interfaces and overridden them in the child class. (override means when a method that has already been
declared in parent class is being defined again in the child class having same name, number and type of parameters, and
return type as the method that it overrides) so, we have re-implemented the walk() and run() method of parent class in the
child class to use them. When the object of child class will call method they will be called without getting ambiguity and will
print the output.
Conclusion :-
• Java does not support "multiple inheritance" (a class can only inherit from
one parent class). However, it can be achieved with help of interfaces,
because the class can implement multiple interfaces.
THANK YOU

Mais conteúdo relacionado

Mais procurados

Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
myrajendra
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 

Mais procurados (20)

Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
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
 
Files in java
Files in javaFiles in java
Files in java
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Java program structure
Java program structure Java program structure
Java program structure
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java package
Java packageJava package
Java package
 

Semelhante a Multiple inheritance in java3 (1).pptx

Semelhante a Multiple inheritance in java3 (1).pptx (20)

4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
 
Ayan Das_25300121057.pptx
Ayan Das_25300121057.pptxAyan Das_25300121057.pptx
Ayan Das_25300121057.pptx
 
Introduction to Inheritance in Java for presentation
Introduction to Inheritance in Java for presentationIntroduction to Inheritance in Java for presentation
Introduction to Inheritance in Java for presentation
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Topic inheritance
Topic  inheritanceTopic  inheritance
Topic inheritance
 
Inheritance in oop
Inheritance in oopInheritance in oop
Inheritance in oop
 
Unit 4
Unit 4Unit 4
Unit 4
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.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 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
 
Inheritance
InheritanceInheritance
Inheritance
 

Último

School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
Kamal Acharya
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DrGurudutt
 

Último (20)

School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
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
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
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
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL 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
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry 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
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
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
 
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.
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 

Multiple inheritance in java3 (1).pptx

  • 1. TOPIC – MULTIPLE INHERITANCE THROUGH INTERFACES PREPARED BY – NAME - PINKI KUMARI ROLL NO. - CSC/21/25
  • 2. INHERITANCE • INHERITANCE – Inheritance is inheriting the properties of one class(Parent class) in the another class(child class). This relation can be defined by using the extends keyword as − public class childClass extends Parentclass{ } • Java is an Object Oriented Programming language and supports the feature of inheritance. We cannot have Multiple Inheritance in Java directly ,but it can be implemented using Interfaces.
  • 3. • The class which inherits the properties is known as sub class or child class and the class whose properties are inherited is super class or parent class. In inheritance a copy of parent class members is created in the child class object. Therefore, using the child class object you can access the members of the both classes . The various types of inheritance in java are :- • Single • Multilevel • hierarchical • Multiple • Hybrid
  • 4. Multiple inheritance is inheriting properties of two or more parent classes to one child class . As given in the below diagram class A and class B is being inherited by the child class C CLASS A CLASS B CLASS C
  • 5. Sample code of how multiple inheritance works in java is given below. First two classes are made ParentA and ParentB and they both have same signature methods walk() . a child class is made which is inheriting both the classes by using a keyword 'extends'
  • 6. OUTPUT : • In the above code the compiler will get confuse which method to call when object of child class calls walk() method and results in compile time error. • The solution to this problem of Multiple inheritance is using Interface
  • 7. INTERFACE IN JAVA Interface is a collection of abstract methods(non-defined methods). A class implements an interface, hence inheriting the abstract methods of the interface. An interface may also contain constants, Variables, default methods, static blocks, methods etc . Interfaces are public ,static and final. The syntax of interface is given below :-
  • 8. To inherit a class in another class we use the keyword extends, And to inherit or to implement a interface in class we use implements keyword. CLASS CLASS INTERFACE CLASS EXTENDS IMPLEMENTS
  • 9. • BELOW IS AN EXAMPLE OF WHERE MULTIPLE INHERITANCE IS ACHIEVED WITH THE HELP OF INTERFACES.
  • 10.
  • 11. OUTPUT :- • hence, in the above code we have achieved Multiple inheritance in java with the help of interfaces where we have declared our methods in the interfaces and overridden them in the child class. (override means when a method that has already been declared in parent class is being defined again in the child class having same name, number and type of parameters, and return type as the method that it overrides) so, we have re-implemented the walk() and run() method of parent class in the child class to use them. When the object of child class will call method they will be called without getting ambiguity and will print the output.
  • 12. Conclusion :- • Java does not support "multiple inheritance" (a class can only inherit from one parent class). However, it can be achieved with help of interfaces, because the class can implement multiple interfaces.