{"id":24980,"date":"2024-04-08T09:07:00","date_gmt":"2024-04-08T03:37:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/"},"modified":"2025-02-05T10:19:38","modified_gmt":"2025-02-05T04:49:38","slug":"inheritance-in-java","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/","title":{"rendered":"Inheritance in Java with Examples"},"content":{"rendered":"\n<p>In<a href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-java\/\"> Object-Oriented Programming<\/a> (OOP) the fundamental idea of Inheritance enables derivative classes to receive the features of base classes. Inheritable code and logical organization emerge through this mechanism which establishes relationships between different classes.<\/p>\n\n\n\n<p>The <strong>extends <\/strong>keyword in Java code enables inheritance through which child classes automatically obtain attributes and behaviors from parent classes.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-title-link\">Java Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn Java the right way! Our course teaches you essential programming skills, from coding basics to complex projects, setting you up for success in the tech industry.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>16.05 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>3 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-button\">\n                Learn Java Programming\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>In this guide, we will learn Java inheritance mechanisms as well as different inheritance types and practical implementation examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"key-concepts-of-inheritance-in-java\">Key Concepts of Inheritance in Java<\/h2>\n\n\n\n<p>Before diving into code, let's define the key terms in inheritance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Superclass (Parent Class):<\/strong> A class whose properties and methods are inherited by another class.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Subclass (Child Class):<\/strong> A class that inherits the properties and methods from a superclass.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Extends <\/strong><strong>Keyword:<\/strong> Used by the subclass to inherit from the superclass.<\/li>\n<\/ul>\n\n\n\n<p>Inheritance makes it easy to reuse existing code and extend functionality.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-of-inheritance-in-java\">Syntax of Inheritance in Java<\/h2>\n\n\n\n<p>The general syntax for creating inheritance in Java is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Parent {\n    \/\/ Parent class code\n}\n\nclass Child extends Parent {\n    \/\/ Child class inherits from Parent class\n}\n<\/pre><\/div>\n\n\n<p>The Child class inherits all non-private members of the Parent class, including fields and methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"simple-example-of-inheritance-in-java\"><strong>Simple Example of Inheritance in Java<\/strong><\/h3>\n\n\n\n<p>Here\u2019s a simple example to demonstrate inheritance:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Animal {\n    void eat() {\n        System.out.println(&quot;This animal eats food.&quot;);\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        System.out.println(&quot;The dog barks.&quot;);\n    }\n}\n\npublic class TestInheritance {\n    public static void main(String&#x5B;] args) {\n        Dog dog = new Dog();\n        dog.eat();  \/\/ Inherited from Animal class\n        dog.bark(); \/\/ Method defined in Dog class\n    }\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThis animal eats food.\nThe dog barks.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-inheritance-in-java\"><strong>Types of Inheritance in Java<\/strong><\/h2>\n\n\n\n<p>Java supports different types of inheritance, each used to model relationships in code. The main types of inheritance are:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-single-inheritance\"><strong>1. Single Inheritance<\/strong><\/h3>\n\n\n\n<p>In single inheritance, a subclass inherits from only one superclass.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Animal {\n    void eat() {\n        System.out.println(&quot;This animal eats food.&quot;);\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        System.out.println(&quot;The dog barks.&quot;);\n    }\n}\n\npublic class TestSingleInheritance {\n    public static void main(String&#x5B;] args) {\n        Dog dog = new Dog();\n        dog.eat();  \/\/ Inherited from Animal class\n        dog.bark(); \/\/ Defined in Dog class\n    }\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThis animal eats food.\nThe dog barks.\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"2-multilevel-inheritance\"><strong>2. Multilevel Inheritance<\/strong><\/h3>\n\n\n\n<p>In multilevel inheritance, a class is derived from another class, which is also a subclass of another class.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Animal {\n    void eat() {\n        System.out.println(&quot;This animal eats food.&quot;);\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        System.out.println(&quot;The dog barks.&quot;);\n    }\n}\n\nclass Puppy extends Dog {\n    void play() {\n        System.out.println(&quot;The puppy plays.&quot;);\n    }\n}\n\npublic class TestMultilevelInheritance {\n    public static void main(String&#x5B;] args) {\n        Puppy puppy = new Puppy();\n        puppy.eat();    \/\/ Inherited from Animal\n        puppy.bark();   \/\/ Inherited from Dog\n        puppy.play();   \/\/ Defined in Puppy\n    }\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThis animal eats food.\nThe dog barks.\nThe puppy plays.\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"3-hierarchical-inheritance\"><strong>3. Hierarchical Inheritance:<\/strong><\/h3>\n\n\n\n<p>In hierarchical inheritance, multiple subclasses inherit from a single superclass.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Animal {\n    void eat() {\n        System.out.println(&quot;This animal eats food.&quot;);\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        System.out.println(&quot;The dog barks.&quot;);\n    }\n}\n\nclass Cat extends Animal {\n    void meow() {\n        System.out.println(&quot;The cat meows.&quot;);\n    }\n}\n\npublic class TestHierarchicalInheritance {\n    public static void main(String&#x5B;] args) {\n        Dog dog = new Dog();\n        dog.eat();    \/\/ Inherited from Animal\n        dog.bark();   \/\/ Defined in Dog\n\n        Cat cat = new Cat();\n        cat.eat();    \/\/ Inherited from Animal\n        cat.meow();   \/\/ Defined in Cat\n    }\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThis animal eats food.\nThe dog barks.\nThis animal eats food.\nThe cat meows.\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"4-multiple-inheritance-using-interfaces\"><strong>4. Multiple Inheritance (Using Interfaces):<\/strong><\/h3>\n\n\n\n<p>Java does not allow multiple inheritance of classes, but it supports multiple inheritance through interfaces. A class can implement multiple interfaces.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ninterface Animal {\n    void eat();\n}\n\ninterface Pet {\n    void play();\n}\n\nclass Dog implements Animal, Pet {\n    public void eat() {\n        System.out.println(&quot;The dog eats.&quot;);\n    }\n    \n    public void play() {\n        System.out.println(&quot;The dog plays.&quot;);\n    }\n}\n\npublic class TestMultipleInheritance {\n    public static void main(String&#x5B;] args) {\n        Dog dog = new Dog();\n        dog.eat();   \/\/ Implemented from Animal interface\n        dog.play();  \/\/ Implemented from Pet interface\n    }\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThe dog eats.\nThe dog plays.\n<\/pre><\/div>\n\n\n<p>While Java does not support multiple inheritance in object-oriented programming, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/cpp-tutorial\/\">C++<\/a> does.<\/p>\n\n\n\n<p><strong>Also Read:<\/strong> <a href=\"https:\/\/www.mygreatlearning.com\/blog\/interface-in-java\/\">Interface in Java<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-constructor-inheritance-in-java\"><strong>5. Constructor Inheritance in Java<\/strong><\/h3>\n\n\n\n<p>In Java, constructors are not inherited by subclasses, but they can be invoked using super(). The constructor of the superclass is called before the subclass's constructor.<\/p>\n\n\n\n<p><strong>Also Read: <\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/constructor-in-java\/\">Constructors in Java<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"benefits-of-using-inheritance-in-java\"><strong>Benefits of Using Inheritance in Java<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Code Reusability:<\/strong> Inheritance allows subclasses to reuse code from the parent class.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Modular Code:<\/strong> Inheritance allows for better organization and structure of code.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Maintainability:<\/strong> Changes in the superclass reflect automatically in the subclasses, making maintenance easier.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-java\/\"><strong>Polymorphism<\/strong><\/a><strong>:<\/strong> Allows the method of a subclass to be invoked, even when using the superclass reference.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"common-inheritance-pitfalls-in-java\">Common Inheritance Pitfalls in Java<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Tight Coupling:<\/strong> Subclasses can become tightly coupled to their superclasses, making changes difficult.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Overridden Method Confusion:<\/strong> If methods are overridden incorrectly, it may lead to unexpected results.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Lack of Flexibility in Inheriting Multiple Classes:<\/strong> Java doesn't allow multiple inheritance directly, which can lead to limitations when modeling complex relationships.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Inheritance is a powerful feature of <strong>Java<\/strong> that supports code reuse and hierarchical classification. You can write more efficient and maintainable code by mastering single, multilevel, hierarchical, and multiple inheritance (through interfaces).<\/p>\n\n\n\n<p>Understanding the super keyword, method overriding, and constructor inheritance will also empower you to use inheritance more effectively.<\/p>\n\n\n\n<p>This brings us to the end of the guide on Inheritance in Java. Hope this helps you to up-skill your Java skills. Also, if you are preparing for Interviews, check out these<a href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-interview-questions\/\"> OOPS Interview questions<\/a> to ace them like a pro.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\"><strong>Frequently Asked Questions<\/strong><\/h2>\n\n\n\n<p><strong>1. Why is multiple inheritance (of classes) not supported in Java?<\/strong><\/p>\n\n\n\n<p>Java does not support multiple inheritance with classes to avoid the <strong>diamond problem<\/strong>, where ambiguity arises if two parent classes have the same method. This ensures cleaner, less error-prone code.<\/p>\n\n\n\n<p><strong>2. How can we achieve multiple inheritance in Java?<\/strong><\/p>\n\n\n\n<p>In Java, multiple inheritance is achieved through <strong>interfaces<\/strong>. A class can implement multiple interfaces, inheriting methods from each without ambiguity.<\/p>\n\n\n\n<p><strong>Also Read:<\/strong> <a href=\"https:\/\/www.mygreatlearning.com\/blog\/abstract-class-vs-interface-in-java\/\">Difference between abstract classes and interfaces in Java<\/a><\/p>\n\n\n\n<p><strong>3. Can constructors be inherited in Java?<\/strong><\/p>\n\n\n\n<p>Constructors are <strong>not inherited<\/strong> in Java, but a subclass can call the constructor of its superclass using the super() keyword to initialize the parent class.<\/p>\n\n\n\n<p><strong>Related Free Courses:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/oops-in-java\">OOPs in Java Free Course<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/inheritance-in-java\">Free Inheritance in Java Course<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\">Free Java Programming Course<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In Object-Oriented Programming (OOP) the fundamental idea of Inheritance enables derivative classes to receive the features of base classes. Inheritable code and logical organization emerge through this mechanism which establishes relationships between different classes. The extends keyword in Java code enables inheritance through which child classes automatically obtain attributes and behaviors from parent classes. In [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":25353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"content_type":[],"class_list":["post-24980","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Inheritance in Java with Examples<\/title>\n<meta name=\"description\" content=\"Inheritance in Java is a concept that acquires the properties from one class to other classes; it&#039;s a parent-child relationship.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inheritance in Java with Examples\" \/>\n<meta property=\"og:description\" content=\"Inheritance in Java is a concept that acquires the properties from one class to other classes; it&#039;s a parent-child relationship.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-08T03:37:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T04:49:38+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1198\" \/>\n\t<meta property=\"og:image:height\" content=\"876\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Inheritance in Java with Examples\",\"datePublished\":\"2024-04-08T03:37:00+00:00\",\"dateModified\":\"2025-02-05T04:49:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/\"},\"wordCount\":682,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-518002738.jpg\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/\",\"name\":\"Inheritance in Java with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-518002738.jpg\",\"datePublished\":\"2024-04-08T03:37:00+00:00\",\"dateModified\":\"2025-02-05T04:49:38+00:00\",\"description\":\"Inheritance in Java is a concept that acquires the properties from one class to other classes; it's a parent-child relationship.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-518002738.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-518002738.jpg\",\"width\":1198,\"height\":876,\"caption\":\"Inheritance in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Inheritance in Java with Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Inheritance in Java with Examples","description":"Inheritance in Java is a concept that acquires the properties from one class to other classes; it's a parent-child relationship.","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:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Inheritance in Java with Examples","og_description":"Inheritance in Java is a concept that acquires the properties from one class to other classes; it's a parent-child relationship.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2024-04-08T03:37:00+00:00","article_modified_time":"2025-02-05T04:49:38+00:00","og_image":[{"width":1198,"height":876,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Inheritance in Java with Examples","datePublished":"2024-04-08T03:37:00+00:00","dateModified":"2025-02-05T04:49:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/"},"wordCount":682,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/","url":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/","name":"Inheritance in Java with Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg","datePublished":"2024-04-08T03:37:00+00:00","dateModified":"2025-02-05T04:49:38+00:00","description":"Inheritance in Java is a concept that acquires the properties from one class to other classes; it's a parent-child relationship.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg","width":1198,"height":876,"caption":"Inheritance in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Inheritance in Java with Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",1198,876,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738-300x219.jpg",300,219,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738-768x562.jpg",768,562,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738-1024x749.jpg",1024,749,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",1198,876,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",1198,876,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",640,468,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",96,70,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-518002738.jpg",150,110,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"In Object-Oriented Programming (OOP) the fundamental idea of Inheritance enables derivative classes to receive the features of base classes. Inheritable code and logical organization emerge through this mechanism which establishes relationships between different classes. The extends keyword in Java code enables inheritance through which child classes automatically obtain attributes and behaviors from parent classes. In&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/24980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=24980"}],"version-history":[{"count":116,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/24980\/revisions"}],"predecessor-version":[{"id":112429,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/24980\/revisions\/112429"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/25353"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=24980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=24980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=24980"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=24980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}