SlideShare a Scribd company logo
1 of 13
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

More Related Content

What's hot

Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
Tech_MX
 

What's hot (20)

Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Data types in java
Data types in javaData types in java
Data types in java
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
OOP java
OOP javaOOP java
OOP java
 
Inheritance
InheritanceInheritance
Inheritance
 
Java packages
Java packagesJava packages
Java packages
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 

Similar to Multiple inheritance in java3 (1).pptx

Similar to 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)
 
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 in java
Inheritance in javaInheritance in java
Inheritance in java
 
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
 

Recently uploaded

INTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSORINTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
TanishkaHira1
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSORINTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
DFT - Discrete Fourier Transform and its Properties
DFT - Discrete Fourier Transform and its PropertiesDFT - Discrete Fourier Transform and its Properties
DFT - Discrete Fourier Transform and its Properties
 
TMU_GDSC_20240509.pdfTMU_GDSC_20240509.pdf
TMU_GDSC_20240509.pdfTMU_GDSC_20240509.pdfTMU_GDSC_20240509.pdfTMU_GDSC_20240509.pdf
TMU_GDSC_20240509.pdfTMU_GDSC_20240509.pdf
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
Overview of Transformation in Computer Graphics
Overview of Transformation in Computer GraphicsOverview of Transformation in Computer Graphics
Overview of Transformation in Computer Graphics
 

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.