{"id":13640,"date":"2020-03-21T14:20:40","date_gmt":"2020-03-21T21:20:40","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=13640"},"modified":"2023-12-01T02:35:18","modified_gmt":"2023-12-01T10:35:18","slug":"java-inheritance","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/java-inheritance\/","title":{"rendered":"Java Inheritance"},"content":{"rendered":"\n<p>Object-oriented programming includes a number of features that help prevent repetitive code. One of these features is inheritance.<\/p>\n\n\n\n<p>This tutorial will discuss, using examples, the basics of inheritance in Java. We will explore how inheritance works, why it is important, method overriding, and how to use the <code>super<\/code> keyword.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Inheritance<\/h2>\n\n\n\n<p>Inheritance is one of the most important features of object-oriented programming. Class inheritance refers to a process whereby you can define a new class based on an existing class.<\/p>\n\n\n\n<p>Through inheritance, <code>subclasses<\/code> can inherit values from <code>parent classes<\/code>, similar to the way children inherit physical traits from parents. We define these two types of classes and their alternative (and interchangeable) names in the table below.<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>Class Type<\/strong><\/td><td><strong>Alternative Name(s)<\/strong><\/td><td><strong>Description [or Definition]<\/strong><\/td><\/tr><tr><td>parent class<\/td><td>base class, superclass<\/td><td>A parent class is a class from which child classes can be derived.<\/td><\/tr><tr><td>subclass<\/td><td>child class<\/td><td>A subclass is a class which inherits its values from a parent class.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Inheritance is important because it allows you to reuse code. If you write code in a parent class, you usually don\u2019t need to write it again in associated child classes; doing so would be inefficient and would make a program more difficult to read.<\/p>\n\n\n\n<p>For example, suppose you are creating a program that stores bank account information for a bank. You may want to have one class that stores regular bank accounts and another class that stores bank accounts for customers who are under 18 years of age (<code>minors<\/code>).<\/p>\n\n\n\n<p>The bank accounts for minors will have many similarities to regular bank accounts\u2014both types of accounts will store names and balances, for example. Therefore, you may decide to make accounts for minors a subclass of a parent bank account class to prevent you from having to repeat code.<\/p>\n\n\n\n<p>In Java, programmers use the <code>extends<\/code> keyword to inherit characteristics from a class. Here\u2019s an example of the extends keyword in action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BankAccount {\n\t\/\/ Code here\n}\nclass ChildAccount extends BankAccount {\n\t\/\/ Code here\n}<\/pre><\/div>\n\n\n\n<p>In this example, BankAccount is the parent class, and ChildAccount is the subclass. Subclasses inherit all the methods and fields of parent classes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Inheritance Example<\/h2>\n\n\n\n<p>You should use inheritance in Java if there is an <code>is-a<\/code> relationship between two classes. Consider the following two examples:<\/p>\n\n\n\n<p><strong>Example 1<\/strong>. In the above section, we talked about bank accounts for minors and regular bank accounts (the ones owned by people aged 18 or over, without restrictions). A bank account for a minor is a type of bank account, and so it can inherit values from the bank account class.&nbsp;<\/p>\n\n\n\n<p><strong>Example 2<\/strong>. Another example would be an iPhone and a phone. The parent class would be called <code>phone<\/code>, and the child class would be called <code>iPhone<\/code>. An iPhone is a phone, and so it could inherit characteristics from the <code>phone<\/code> parent class.<\/p>\n\n\n\n<p>Let\u2019s walk through an example to demonstrate how inheritance works in Java. We\u2019ll return to the bank account example from earlier.<\/p>\n\n\n\n<p>Suppose we want to create a program that stores banking information for bank customers. The bank for which we are creating this program allows customers to have one of two account types: a regular account (for someone aged 18 or over, which has no restrictions) or an account for a minor. Regular accounts are for customers over the age of 18. Accounts for minors are for customers under the age of 18. Accounts for minors have a few restrictions.<\/p>\n\n\n\n<p>Because an account for a minor has many similarities to a bank account\u2014an account for a minor is a bank account\u2014we can use inheritance. Here\u2019s an example of inheritance in use in the program we just described:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BankAccount {\n\tpublic void checkBalance() {\n\t\tSystem.out.println(\"Your balance is: $X\");\n\t}\n\tpublic void viewDetails() {\n\t\tSystem.out.println(\"Name: Helen Clarkson\");\n\t\tSystem.out.println(\"Address: 123 Main Street\");\n\t\tSystem.out.println(\"Overdraft Limit: $0\");\n\t}\n}\nclass ChildAccount extends BankAccount {\n\tpublic void setSavingsAmount() {\n\t\tSystem.out.println(\"Savings amount set to $Y.\");\n\t}\n}\nclass Main {\n\tpublic static void main(String[] args) {\n\t\tChildAccount helen = new ChildAccount();\n\t\thelen.checkBalance();\n\t\thelen.viewDetails();\n\t\thelen.setSavingsAmount();\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Your balance is: $X\nName: Helen Clarkson\nAddress: 123 Main Street\nOverdraft Limit: $0\nSavings amount set to $Y.<\/pre><\/div>\n\n\n\n<p>In this example, we defined three classes. They are:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>BankAccount<\/strong>. BankAccount is a parent class. This class has two methods: <code>checkBalance()<\/code> and <code>viewDetails()<\/code>.<\/li>\n\n\n\n<li><strong>ChildAccount<\/strong>. ChildAccount is a class of BankAccount for minors and inherits the methods <code>checkBalance()<\/code> and <code>viewDetails()<\/code> from the BankAccount class. In addition, ChildAccount has its own method: <code>setSavingsAmount()<\/code>.<\/li>\n\n\n\n<li><strong>Main<\/strong>. We also declare a class called Main in which the code for our main program is stored.&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>In the main program, we create an instance of the ChildAccount class and call it helen. Helen is the name of our customer. Then, we invoke each method available to the child class.<\/p>\n\n\n\n<p>As you can see in the code above, the helen variable can access both <code>checkBalance()<\/code> and <code>viewDetails()<\/code>, which are part of the BankAccount parent class, as well as the <code>setSavingsAmount()<\/code> method, which is part of the ChildAccount child class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Method Overriding<\/h2>\n\n\n\n<p>In the above example, we talked about how a subclass inherits the values of its parent class. But what happens if the same method is defined in both a subclass and its parent class?<\/p>\n\n\n\n<p>In this case, the subclass will override the method in the superclass. For instance, suppose we wanted the <code>viewDetails()<\/code> method to be different for a ChildAccount. Regular BankAccounts can access overdrafts, and perhaps we don\u2019t want any ChildAccount to be able to see an overdraft limit since they are not eligible for this service.<\/p>\n\n\n\n<p>We could use the following code to override the <code>viewDetails()<\/code> method in the child class: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BankAccount {\n\tpublic void checkBalance() {\n\t\tSystem.out.println(\"Your balance is: $X\");\n\t}\n\tpublic void viewDetails() {\n\t\tSystem.out.println(\"Name: Helen Clarkson\");\n\t\tSystem.out.println(\"Address: 123 Main Street\");\n\t\tSystem.out.println(\"Overdraft Limit: $0\");\n\t}\n}\nclass ChildAccount extends BankAccount {\n\tpublic void setSavingsAmount() {\n\t\tSystem.out.println(\"Savings amount set to $Y.\");\n\t}\n\t@Override\n\tpublic void viewDetails() {\n\t\tSystem.out.println(\"Name: Helen Clarkson\");\n\t\tSystem.out.println(\"Address: 123 Main Street\");\n\t}\n}\nclass Main {\n\tpublic static void main(String[] args) {\n\t\tChildAccount helen = new ChildAccount();\n\t\thelen.checkBalance();\n\t\thelen.viewDetails();\n\t\thelen.setSavingsAmount();\n\t}\n}<\/pre><\/div>\n\n\n\n<p>When we run our code, our program returns the following response:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Your balance is: $X\nName: Helen Clarkson\nAddress: 123 Main Street\nSavings amount set to $Y.<\/pre><\/div>\n\n\n\n<p>The response is the same as the one in our first example except for one difference: the console does not print the customer\u2019s overdraft limit.<\/p>\n\n\n\n<p>In this example, <code>viewDetails()<\/code> is declared in both the subclass ChildAccount and the superclass BankAccount.<\/p>\n\n\n\n<p>When we declared <code>viewDetails()<\/code> in the ChildAccount, we used the @Override statement, which tells the program to override the superclass\u2019 method. So, this means that when we reference the <code>viewDetails()<\/code> method for Helen\u2019s account, the program references the<code> viewDetails()<\/code> method in the ChildAccount class instead of the <code>viewDetails()<\/code> method in the BankAccount class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Super Keyword<\/h2>\n\n\n\n<p>In Java, the super keyword is used to access an overwritten parent class method.<\/p>\n\n\n\n<p>Let\u2019s return to the bank account example. Suppose we decide that, instead of hiding the overdraft limit statement from customers who are minors, we want to show it and print a message to the user, telling them: <code>You are not eligible for an overdraft until you reach the age of 18.<\/code><\/p>\n\n\n\n<p>If this is the case, we will still want to access the code in the <code>viewDetails()<\/code> method of the BankAccount class, but we want to add an extra message that only appears in instances of the ChildAccount class. We could do so using this code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BankAccount {\n\t\/\/ Code here\n}\nclass ChildAccount extends BankAccount {\n\t\/\/ Code here\n\t@Override\n\tpublic void viewDetails() {\n\t\tsuper.viewDetails();\n\t\tSystem.out.println(\"You are not eligible for an overdraft until you reach the age of 18.\");\n\t}\n}\nclass Main {\n\tpublic static void main(String[] args) {\n\t\tChildAccount helen = new ChildAccount();\n\t\thelen.checkBalance();\n\t\thelen.viewDetails();\n\t\thelen.setSavingsAmount();\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Your balance is: $X\nName: Helen Clarkson\nAddress: 123 Main Street\nOverdraft Limit: $0\nYou are not eligible for an overdraft until you reach the age of 18.\nSavings amount set to $Y.<\/pre><\/div>\n\n\n\n<p>In this example, we used the super keyword to execute the <code>viewDetails()<\/code> method from the BankAccount class, but from within the ChildAccount class.<\/p>\n\n\n\n<p>So, when we execute <code>helen.viewDetails()<\/code> to view Helen\u2019s account details, the ChildAccount <code>viewDetails()<\/code> method executes. In the ChildAccount <code>viewDetails()<\/code> method, we use the super keyword, which causes the BankAccount <code>viewDetails()<\/code> method to be run. This returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Name: Helen Clarkson\nAddress: 123 Main Street\nOverdraft Limit: $0<\/pre><\/div>\n\n\n\n<p>Then, after the BankAccount <code>viewDetails()<\/code> method is executed, the program continues to execute the ChildAccount <code>viewDetails()<\/code> method. This results in the console printing the following message:<\/p>\n\n\n\n<p>You are not eligible for an overdraft until you reach the age of 18.<\/p>\n\n\n\n<p>After the <code>viewDetails()<\/code> method in the ChildAccount class executes, our program continues to run.<\/p>\n\n\n\n<iframe loading=\"lazy\" frameborder=\"0\" width=\"100%\" height=\"400px\" src=\"https:\/\/repl.it\/@careerkarma\/Java-Inheritance?lite=true\"><\/iframe>\n<br>\n<br>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Inheritance is used in object-oriented programming to define new classes from existing classes. This allows you to reuse code, thereby allowing you to write more efficient and readable code.<\/p>\n\n\n\n<p>This tutorial discussed the basics of inheritance, how to use inheritance in Java, method overriding, and the super keyword. Now that you\u2019ve read this tutorial, you are ready to start working with inheritance like a Java professional!<\/p>\n","protected":false},"excerpt":{"rendered":"Object-oriented programming includes a number of features that help prevent repetitive code. One of these features is inheritance. This tutorial will discuss, using examples, the basics of inheritance in Java. We will explore how inheritance works, why it is important, method overriding, and how to use the super keyword. Java Inheritance Inheritance is one of&hellip;","protected":false},"author":240,"featured_media":13641,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17289],"tags":[],"class_list":{"0":"post-13640","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-java"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Java","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Java Inheritance: The Complete Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Inheritance\" \/>\n<meta property=\"og:description\" content=\"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-21T21:20:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:35:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"681\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Java Inheritance\",\"datePublished\":\"2020-03-21T21:20:40+00:00\",\"dateModified\":\"2023-12-01T10:35:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\"},\"wordCount\":1207,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\",\"name\":\"Java Inheritance: The Complete Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg\",\"datePublished\":\"2020-03-21T21:20:40+00:00\",\"dateModified\":\"2023-12-01T10:35:18+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/java-inheritance\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg\",\"width\":1020,\"height\":681},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-inheritance\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\/\/careerkarma.com\/blog\/java\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Inheritance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java Inheritance: The Complete Guide | Career Karma","description":"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.","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:\/\/careerkarma.com\/blog\/java-inheritance\/","og_locale":"en_US","og_type":"article","og_title":"Java Inheritance","og_description":"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.","og_url":"https:\/\/careerkarma.com\/blog\/java-inheritance\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-03-21T21:20:40+00:00","article_modified_time":"2023-12-01T10:35:18+00:00","og_image":[{"width":1020,"height":681,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Java Inheritance","datePublished":"2020-03-21T21:20:40+00:00","dateModified":"2023-12-01T10:35:18+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/"},"wordCount":1207,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/java-inheritance\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/","url":"https:\/\/careerkarma.com\/blog\/java-inheritance\/","name":"Java Inheritance: The Complete Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg","datePublished":"2020-03-21T21:20:40+00:00","dateModified":"2023-12-01T10:35:18+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Inheritance is a core concept in object-oriented programming. On Career Karma, learn how to use inheritance and how to work with subclasses and parent classes in your Java code.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/java-inheritance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/photo-of-laptops-on-top-of-wooden-table-3183151.jpg","width":1020,"height":681},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/java-inheritance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/careerkarma.com\/blog\/java\/"},{"@type":"ListItem","position":3,"name":"Java Inheritance"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=13640"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13640\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=13640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=13640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=13640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}