{"id":25539819,"date":"2022-08-28T01:27:15","date_gmt":"2022-08-27T19:57:15","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25539819"},"modified":"2022-11-23T14:37:23","modified_gmt":"2022-11-23T09:07:23","slug":"hybrid-inheritance-in-java-all-you-need-to-know","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/","title":{"rendered":"Hybrid Inheritance in Java- All you need to know"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e083174b041\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e083174b041\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Inheritance\" >Inheritance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Hybrid_Inheritance_in_Java\" >Hybrid Inheritance in Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Hybrid_Inheritance_in_Java_using_Single_and_Multiple_Inheritance\" >Hybrid Inheritance in Java using Single and Multiple Inheritance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Hybrid_Inheritance_in_Java_using_Multilevel_and_Hierarchical_Inheritance\" >Hybrid Inheritance in Java using Multilevel and Hierarchical Inheritance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Implementation_of_Hybrid_Inheritance_with_Classes\" >Implementation of Hybrid Inheritance with Classes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Implementation_of_Hybrid_Inheritance_with_Interfaces\" >Implementation of Hybrid Inheritance with\u00a0Interfaces<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<header class=\"entry-header\">\n<div class=\"parent-heading\">\n<div class=\"line\"><\/div>\n<\/div>\n<p>Java is an object-oriented programming language. Everything in Java is an object, all the programs, codes, and data reside within classes and objects.\u00a0 Inheritance, Polymorphism, Encapsulation, Abstraction, classes, and objects are few important concepts of Object-Oriented Programming.\u00a0 OOPs is a really important topic from an interview perspective.<\/p>\n<p>As in real life, a child inherits some features from its parents; Similarly, in Object Oriented Programming language, a class may inherit from its parent class. In Java, every class has a superclass\/parent class. The Object class is the root of the entire class hierarchy in Java.<\/p>\n<p>This blog will discuss hybrid inheritance in Java in detail, along with codes and examples.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<div class=\"parent-heading\">\n<h2 id=\"2.\"><span class=\"ez-toc-section\" id=\"Inheritance\"><\/span><strong>Inheritance<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\"><\/div>\n<\/div>\n<p>Inheritance is a crucial part of object-oriented programming. The process of inheriting the properties and behavior of an existing class into a new class is known as inheritance. We will reuse the original class methods and fields in a new class when we inherit the class. Inheritance may also be described as the\u00a0<strong>Is-A<\/strong>\u00a0relationship, also known as the\u00a0<strong>parent-child<\/strong>\u00a0relationship.<\/p>\n<p>A real-world example of Inheritance is a relationship between a daughter and her Mother. A daughter inherits features from her mother, the mother, in turn, has inherited the features from her mother, and the cycle goes on. A technical example of inheritance is as follows: The Integer Class is the child class of the Number class. The Number class is the Child Class of the Object Class.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<p>Java supports the following types of inheritance:<\/p>\n<ol>\n<li>Single Inheritance<\/li>\n<li>Multi-level Inheritance<\/li>\n<li>Hierarchical Inheritance<\/li>\n<li>Hybrid Inheritance<\/li>\n<li>Multiple Inheritance(not support by using classes, but its possible using interfaces)<\/li>\n<\/ol>\n<div class=\"parent-heading\">\n<h2 id=\"3.\"><span class=\"ez-toc-section\" id=\"Hybrid_Inheritance_in_Java\"><\/span><strong>Hybrid Inheritance in Java<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\"><\/div>\n<\/div>\n<p>Hybrid inheritance in Java is a combination of two or more types of inheritances. The purpose of using hybrid inheritance in Java is to modularize the codebase into well-defined classes and provide code reusability.<\/p>\n<p>This blog will discuss hybrid inheritance in Java using a combination of the following inheritances:<\/p>\n<ol>\n<li>Hybrid Inheritance in Java using Single and Multiple Inheritance.<\/li>\n<li>Hybrid Inheritance in Java using Multilevel and Hierarchical Inheritance.<\/li>\n<\/ol>\n<div class=\"parent-heading\">\n<h2 id=\"4.\"><span class=\"ez-toc-section\" id=\"Hybrid_Inheritance_in_Java_using_Single_and_Multiple_Inheritance\"><\/span><strong>Hybrid Inheritance in Java using Single and Multiple Inheritance<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\"><\/div>\n<\/div>\n<p>Consider the following example wherein\u00a0a combination of single and multiple inheritances is used to achieve hybrid inheritance in Java:<\/p>\n<p>There is a HumanBody class that has some functionality like eating(), walking(), dancing(), etc., and some fields like bloodPressure, normalOxygenLevel, bonesCount, etc. There are two child classes of the HumanBody class, the Female and Male class. The Male class and the Female class will inherit all the functions and the fields of the HumanBody class. This is a simple example of Single Inheritance in Java.<\/p>\n<p>&nbsp;<\/p>\n<figure class=\"image\"><img decoding=\"async\" src=\"https:\/\/files.codingninjas.in\/article_images\/hybrid-inheritance-in-java-0-1660031085.jpg\" alt=\"single inheritance\" \/><\/figure>\n<p>&nbsp;<\/p>\n<p>Now consider that the Male and Female classes have a child with the class name as Child. This is a simple example of multiple inheritances in Java. The relationship between the Male, Female, and Child classes is visualized below:<\/p>\n<p>&nbsp;<\/p>\n<figure class=\"image\"><img decoding=\"async\" src=\"https:\/\/files.codingninjas.in\/article_images\/hybrid-inheritance-in-java-1-1660031086.jpg\" alt=\"multiple inheritance\" \/><\/figure>\n<p>&nbsp;<\/p>\n<p>The combined relationship between the HumanBody, Male, Female, and Child classes is visualized below. It is an example of Hybrid Inheritance using the combination of Single and Multiple Inheritances.<\/p>\n<p>&nbsp;<\/p>\n<figure class=\"image\"><img decoding=\"async\" src=\"https:\/\/files.codingninjas.in\/article_images\/hybrid-inheritance-in-java-2-1660031086.jpg\" alt=\"hybrid inheritance\" \/><\/figure>\n<p>However, we know that multiple inheritances are not possible in Java. So this analogy has to be incorrect.<\/p>\n<p>Well, the only incorrect thing is that, instead of classes, interfaces will be used to achieve multiple inheritances.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre><code class=\"language-plaintext\">public class A\r\n{\r\n\u00a0\u00a0\u00a0\u00a0\/\/ Methods and Fields of class A\r\n}\r\npublic interface interfaceB\u00a0\r\n{\r\n\u00a0\u00a0\/\/ Methods and Fields of InterfaceB\r\n}\r\npublic interface interfaceC\u00a0\r\n{\r\n\u00a0\u00a0\/\/ Methods and Fields of InterfaceC\r\n}\r\npublic class D extends A implements InterfaceB,InterfaceC\r\n{\r\n\u00a0\u00a0\u00a0\u00a0\/\/ Implementation of the method defined in Interfaces, InterfaceB and InterfaceC\r\n\r\n\u00a0\u00a0\u00a0\u00a0\/\/ Methods of class D\u00a0\u00a0\u00a0\r\n}<\/code><\/pre>\n<p>The below program demonstrates hybrid inheritance using a combination of single inheritance and multiple inheritances using Interfaces.<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"language-java\">class HumanBody\r\n{\r\n\u00a0\u00a0\u00a0public void displayHuman()\r\n\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(\"Method defined inside HumanBody class\");\r\n\u00a0\u00a0\u00a0}\r\n}\r\ninterface Male\r\n{\r\n\u00a0public void show();\r\n}\r\ninterface Female\r\n{\r\n\u00a0public void show();\r\n}\r\n\u00a0\r\n\/\/ Single Inheritance is the relationship between Child \/\/ class and HumanBody class.\r\n\/\/ Implementing Male and Female interface is Multiple \/\/ Inheritance\r\npublic class Child extends HumanBody implements Male, Female\r\n{\r\n\u00a0public void show()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Implementation of show() method defined in interfaces Male and Female\");\r\n\u00a0}\u00a0\u00a0\r\n\u00a0\r\n\u00a0public void displayChild()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Method defined inside Child class\");\r\n\u00a0}\r\n\u00a0\r\n\u00a0public static void main(String[]args)\r\n\u00a0{\r\n\u00a0\u00a0\u00a0Child obj = new Child();\r\n\u00a0\u00a0\u00a0System.out.println(\"Implementation of Hybrid Inheritance in Java\");\r\n\u00a0\u00a0\u00a0obj.show();\r\n\u00a0\u00a0\u00a0obj.displayChild();\r\n\u00a0}\r\n}\r\n<\/code><\/pre>\n<p>The output of the above program is:<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"language-plaintext\">Implementation of Hybrid Inheritance in Java\r\nImplementation of show() method defined in interfaces Male and Female\r\nMethod defined inside Child class<\/code><\/pre>\n<div class=\"parent-heading\">\n<h2 id=\"5.\"><span class=\"ez-toc-section\" id=\"Hybrid_Inheritance_in_Java_using_Multilevel_and_Hierarchical_Inheritance\"><\/span><strong>Hybrid Inheritance in Java using Multilevel and Hierarchical Inheritance<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\"><\/div>\n<\/div>\n<p>Hybrid Inheritance can also be achieved using a combination of Multilevel and Hierarchical inheritance. A real-world example will be, Son class inherits the Father class, Father class inherits the GrandFather class. This relation is of Multilevel inheritance. Likewise, A Daughter Class inherits the Father class, which in turn inherits the GrandFather class.<\/p>\n<p>On the other hand, Son and Daughter both inherit Father class, and this relation is of Hierarchical Inheritance.<\/p>\n<p>A combination of both the inheritance relation will make Hybrid inheritance.<\/p>\n<p>&nbsp;<\/p>\n<figure class=\"image image_resized\"><img decoding=\"async\" src=\"https:\/\/files.codingninjas.in\/article_images\/hybrid-inheritance-in-java-3-1660031086.jpg\" alt=\"hybrid inheritance\" \/><\/figure>\n<p>The below program demonstrates Hybrid inheritance using a combination of Multilevel and Hierarchical inheritance.<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"language-plaintext\">class GrandFather\r\n{\r\n\u00a0public void printGrandFather()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"GrandFather's class\");\r\n\u00a0}\r\n}\r\n\u00a0\r\nclass Father extends GrandFather\r\n{\r\n\u00a0public void printFather()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Father class has inherited GrandFather class\");\r\n\u00a0}\r\n}\r\n\u00a0\r\nclass Son extends Father\r\n{\r\n\u00a0public Son()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Inside the Son Class\");\r\n\u00a0}\r\n\u00a0\r\n\u00a0public void printSon()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Son class has inherited Father class\");\r\n\u00a0}\r\n}\r\n\u00a0\r\nclass Daughter extends Father\r\n{\r\n\u00a0public Daughter()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Inside the Daughter Class\");\r\n\u00a0}\r\n\u00a0\r\n\u00a0public void printDaughter()\r\n\u00a0{\r\n\u00a0\u00a0\u00a0System.out.println(\"Son class has inherited Father class\");\r\n\u00a0}\r\n}\r\n\u00a0\r\npublic class HybridInheritance\r\n{\r\n\u00a0public static void main(String[]args)\r\n\u00a0{\r\n\u00a0\u00a0\u00a0Son obj = new Son();\r\n\u00a0\u00a0\u00a0obj.printSon();\u00a0 \/\/ Accessing Son class method\r\n\u00a0\u00a0\u00a0obj.printFather();\u00a0 \/\/ Accessing Father class method\r\n\u00a0\u00a0\u00a0obj.printGrandFather();\u00a0 \/\/ Accessing GrandFather class method\r\n\u00a0\r\n\u00a0\u00a0\u00a0Daughter obj2 = new Daughter();\r\n\u00a0\u00a0\u00a0obj2.printDaughter();\u00a0 \/\/ Accessing Daughter class method\r\n\u00a0\u00a0\u00a0obj2.printFather();\u00a0 \u00a0 \/\/ Accessing Father class method\r\n\u00a0\u00a0\u00a0obj2.printGrandFather(); \u00a0 \/\/ Accessing GrandFather class method\u00a0\r\n\u00a0\r\n\u00a0}\r\n}\r\n<\/code><\/pre>\n<p>The output of the above program is:<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"language-plaintext\">Inside the Son Class\r\nSon class has inherited Father class\r\nFather class has inherited GrandFather class\r\nGrandFather's class\r\nInside the Daughter Class\r\nSon class has inherited Father class\r\nFather class has inherited GrandFather class\r\nGrandFather's class<\/code><\/pre>\n<div class=\"parent-heading\">\n<h2 id=\"6.\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span><strong>Frequently Asked Questions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\"><\/div>\n<\/div>\n<h3 id=\"6.1.\"><strong>What are the different types of hybrid inheritance?<\/strong><\/h3>\n<p>Hybrid Inheritance in Java is a combination of two or more inheritances. It can be done using a combination of the following inheritances.<br \/>\n1. Single and Multiple Inheritance<br \/>\n2. Multilevel and Hierarchical Inheritance<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/p>\n<h3 id=\"6.2.\"><strong>Why is there no hybrid inheritance in java?<\/strong><\/h3>\n<p>Java supports hybrid Inheritance. However, Java does not support Multiple Inheritance with classes, so in order to achieve hybrid inheritance, multiple inheritances with classes should not be used. Multiple Inheritance with Interfaces is possible.<\/p>\n<h3 id=\"6.3.\"><strong>What is hybrid inheritance?<\/strong><\/h3>\n<p>The combination of two or more inheritances is called hybrid inheritance. It provides code reusability.<\/p>\n<h3 id=\"6.4.\"><strong>Why are pointers not used in Java?<\/strong><\/h3>\n<p>Java is a highly secured programming language. Pointers provide direct access to a memory address, and an arbitrary memory location can be accessed, and read and write operations can be performed on it. For the purpose of security Java does not support Pointers.<\/p>\n<\/header>\n<div class=\"entry-content\">\n<h2><span class=\"ez-toc-section\" id=\"Implementation_of_Hybrid_Inheritance_with_Classes\"><\/span><strong>Implementation of Hybrid Inheritance with Classes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"prettyprint\">public class ClassA \r\n{\r\n    public void dispA()\r\n    {\r\n        System.out.println(\"disp() method of ClassA\");\r\n    }\r\n}\r\npublic class ClassB extends ClassA \r\n{\r\n    public void show()\r\n    {\r\n        System.out.println(\"show() method of ClassB\");\r\n    }\r\n    public void dispB()\r\n    {\r\n        System.out.println(\"disp() method of ClassB\");\r\n    }\r\n}\r\npublic class ClassC extends ClassA\r\n{\r\n    public void show()\r\n    {\r\n        System.out.println(\"show() method of ClassC\");\r\n    }\r\n    public void dispC()\r\n    {\r\n        System.out.println(\"disp() method of ClassC\");\r\n    }\r\n}\r\npublic class ClassD extends ClassB,ClassC\r\n{\r\n    public void dispD()\r\n    {\r\n        System.out.println(\"disp() method of ClassD\");\r\n    }\r\n    public static void main(String args[])\r\n    {\r\n          ClassD d = new ClassD();\r\n          d.dispD();\r\n          d.show();\/\/Confusion happens here which show method to call\r\n    }\r\n}<\/pre>\n<p><strong>Output :<\/strong><\/p>\n<pre class=\"prettyprint\">Error!!<\/pre>\n<p>We all know that we cannot extend\u00a0<strong>ClassB<\/strong>\u00a0and\u00a0<strong>ClassC<\/strong>\u00a0to\u00a0<strong>ClassD<\/strong>\u00a0at the same time but the point to be noted here is why it is not allowed. Since we have same\u00a0<strong>show()<\/strong>\u00a0method in both\u00a0<strong>ClassB<\/strong>\u00a0and\u00a0<strong>ClassD<\/strong>\u00a0compiler will not be able to differentiate which method to call whereas if we are using interface we can avoid that ambiguity.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Implementation_of_Hybrid_Inheritance_with_Interfaces\"><\/span><strong>Implementation of Hybrid Inheritance with\u00a0Interfaces<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"prettyprint\">public class ClassA \r\n{\r\n    public void dispA()\r\n    {\r\n        System.out.println(\"disp() method of ClassA\");\r\n    }\r\n}\r\npublic interface InterfaceB \r\n{\r\n    public void show();\r\n}\r\npublic interface InterfaceC \r\n{\r\n    public void show();\r\n}\r\npublic class ClassD extends ClassA implements InterfaceB,InterfaceC\r\n{\r\n    public void show()\r\n    {\r\n        System.out.println(\"show() method implementation\");\r\n    }\r\n    public void dispD()\r\n    {\r\n        System.out.println(\"disp() method of ClassD\");\r\n    }\r\n    public static void main(String args[])\r\n    {\r\n        ClassD d = new ClassD();\r\n        d.dispD();\r\n        d.show();\r\n    }\r\n}<\/pre>\n<p><strong>Output :<\/strong><\/p>\n<pre class=\"prettyprint\">disp() method of ClassD\r\nshow() method implementation<\/pre>\n<p>As we can see in the above code the\u00a0<strong>ClassD<\/strong>\u00a0has implemented both the\u00a0<strong>interfaces InterfaceB\u00a0<\/strong>and<strong>\u00a0InterfaceC.<\/strong>\u00a0In this case we\u00a0didn\u2019t\u00a0have\u00a0ambiguity\u00a0even though both the interfaces are having\u00a0same method.<\/p>\n<header class=\"entry-header\">\n<div class=\"parent-heading\">\n<h2 id=\"7.\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"line\">In this blog, we discussed about Hybrid Inheritance in Java in detail. With this done, you may now switch to learn more about Object-Oriented Programming concepts.<\/div>\n<\/div>\n<p>Questions related to Inheritance are frequently asked in technical rounds of big companies.<\/p>\n<p>Do not stop here !!\u00a0Remember, Practice makes perfect !!<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<\/header>\n<div class=\"entry-content\">\n<p>Hybrid\u00a0Inheritance\u00a0is a combination of both\u00a0Single\u00a0Inheritance\u00a0and\u00a0Multiple Inheritance.\u00a0\u00a0Since in\u00a0Java , Multiple Inheritance\u00a0is not supported directly we can achieve Hybrid inheritance also through\u00a0Interfaces\u00a0only.\u00a0<span id=\"more-1948\"><\/span><\/p>\n<div class=\"code-block code-block-1\">\n<div class=\"adsbyvli\" data-ad-slot=\"vi_124847929\" data-id=\"vi_124847929_1\">\n<div id=\"google_ads_iframe_\/22652820046\/1248_Javainterviewpoint.com\/1248_Javainterviewpoint.com_1_45__container__\"><\/div>\n<\/div>\n<\/div>\n<p><a href=\"https:\/\/javainterviewpoint.com\/\/wp-content\/uploads\/2015\/07\/Hybrid_Inheritance_in_Java.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1904 lazyloaded\" src=\"https:\/\/javainterviewpoint.com\/\/wp-content\/uploads\/2015\/07\/Hybrid_Inheritance_in_Java.png\" srcset=\"https:\/\/www.javainterviewpoint.com\/wp-content\/uploads\/2015\/07\/Hybrid_Inheritance_in_Java.png 648w, https:\/\/www.javainterviewpoint.com\/wp-content\/uploads\/2015\/07\/Hybrid_Inheritance_in_Java-300x188.png 300w\" alt=\"Hybrid_Inheritance_in_Java\" width=\"423\" height=\"265\" data-ll-status=\"loaded\" \/><\/a><br \/>\nAs we can see in the above diagram\u00a0<strong>ClassA<\/strong>\u00a0is the Parent for both\u00a0<strong>ClassB<\/strong>\u00a0and\u00a0<strong>ClassC<\/strong>\u00a0which is Single Inheritance and again\u00a0<strong>ClassB<\/strong>\u00a0and\u00a0<strong>ClassC<\/strong>\u00a0again act as Parent for\u00a0<strong>ClassC <\/strong>(Multiple Inheritance which is not supported by Java). Lets now see below code on what will happen if we go for implementing Hybrid Inheritance with both classes and interfaces.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Java is an object-oriented programming language. Everything in Java is an object, all the programs, codes, and data reside within classes and objects.\u00a0 Inheritance, Polymorphism, Encapsulation, Abstraction, classes, and objects are few important concepts of Object-Oriented Programming.\u00a0 OOPs is a really important topic from an interview perspective. As in real life, a child inherits some [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25539906,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1882],"tags":[],"class_list":["post-25539819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-java-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hybrid Inheritance in Java- All you need to know - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hybrid Inheritance in Java- All you need to know - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Java is an object-oriented programming language. Everything in Java is an object, all the programs, codes, and data reside within classes and objects.\u00a0 Inheritance, Polymorphism, Encapsulation, Abstraction, classes, and objects are few important concepts of Object-Oriented Programming.\u00a0 OOPs is a really important topic from an interview perspective. As in real life, a child inherits some [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-27T19:57:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-23T09:07:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"Hybrid Inheritance in Java- All you need to know\",\"datePublished\":\"2022-08-27T19:57:15+00:00\",\"dateModified\":\"2022-11-23T09:07:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\"},\"wordCount\":1118,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png\",\"articleSection\":[\"Articles\",\"Java Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\",\"url\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\",\"name\":\"Hybrid Inheritance in Java- All you need to know - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png\",\"datePublished\":\"2022-08-27T19:57:15+00:00\",\"dateModified\":\"2022-11-23T09:07:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png\",\"width\":820,\"height\":615,\"caption\":\"Hybrid Inheritance in Java- All you need to know\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Hybrid Inheritance in Java- All you need to know\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hybrid Inheritance in Java- All you need to know - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/","og_locale":"en_US","og_type":"article","og_title":"Hybrid Inheritance in Java- All you need to know - Entri Blog","og_description":"Java is an object-oriented programming language. Everything in Java is an object, all the programs, codes, and data reside within classes and objects.\u00a0 Inheritance, Polymorphism, Encapsulation, Abstraction, classes, and objects are few important concepts of Object-Oriented Programming.\u00a0 OOPs is a really important topic from an interview perspective. As in real life, a child inherits some [&hellip;]","og_url":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-08-27T19:57:15+00:00","article_modified_time":"2022-11-23T09:07:23+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"Hybrid Inheritance in Java- All you need to know","datePublished":"2022-08-27T19:57:15+00:00","dateModified":"2022-11-23T09:07:23+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/"},"wordCount":1118,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png","articleSection":["Articles","Java Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/","url":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/","name":"Hybrid Inheritance in Java- All you need to know - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png","datePublished":"2022-08-27T19:57:15+00:00","dateModified":"2022-11-23T09:07:23+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/Hybrid-Inheritance-in-Java-All-you-need-to-know.png","width":820,"height":615,"caption":"Hybrid Inheritance in Java- All you need to know"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/hybrid-inheritance-in-java-all-you-need-to-know\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"Hybrid Inheritance in Java- All you need to know"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25539819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25539819"}],"version-history":[{"count":5,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25539819\/revisions"}],"predecessor-version":[{"id":25547997,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25539819\/revisions\/25547997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25539906"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25539819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25539819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25539819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}