{"id":76930,"date":"2020-02-28T14:10:32","date_gmt":"2020-02-28T08:40:32","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=76930"},"modified":"2020-02-28T14:10:32","modified_gmt":"2020-02-28T08:40:32","slug":"java-method-overriding","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/","title":{"rendered":"Java Method Overriding &#8211; Learn its Importance and Rules with Coding Examples"},"content":{"rendered":"<p>In the last tutorial, we have learned the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/java-polymorphism\/\"><em><strong>Polymorphism in Java.<\/strong><\/em><\/a> We covered the two kinds of polymorphism in Java and the process of implementing them in Java.<\/p>\n<p>We know that static polymorphism can be achieved at compile time with the help of Method Overloading, while dynamic polymorphism can be achieved at run\/execution time with the help of Method Overriding.<\/p>\n<p>In this article, we will study in detail about Method Overriding in Java with its rules and examples.<\/p>\n<h3>What is Java Method Overriding?<\/h3>\n<p>Method Overriding is a feature that allows us to redefine the method in the subclass or derived class which is already defined in its parent class or superclass.<\/p>\n<p>In any object-oriented programming language, we can implement Method Overriding only when two classes have \u2018Is-a\u2019 relationship of inheritance between them.<\/p>\n<p>Using Method Overriding, a derived class or child class can provide a specific implementation of a function or method that is already defined in one of its parent classes.<\/p>\n<p>When a method of a derived or sub-class has the same name, same return type or signature and with the same arguments as a method in its parent class, then we say that the method in the superclass is being overridden by the method in the subclass.<\/p>\n<p>This concept when a method of a subclass overrides the same method in its superclass, but with a different implementation, is called <strong>Method Overriding.<\/strong><\/p>\n<h3>Importance of Java Method Overriding<\/h3>\n<p>Now you must be thinking about what is the need for using Method Overriding. So let\u2019s discuss the uses and importance of Method Overriding in Java.<\/p>\n<ul>\n<li>One of the benefits of Method Overriding is the ability to provide a specific implementation or definition of a method in a subclass, which already exists in its superclass. This method can be overridden in the subclass according to the requirement.<\/li>\n<li>It is also useful in the implementation of Runtime or Dynamic Polymorphism in which the method is invoked during the execution of the program. Basically, the type of object and not the type of reference variable decides which method is going to be executed at the runtime.<\/li>\n<\/ul>\n<p>The following figure illustrates the Method Overriding in Java where the method<strong> draw()<\/strong> is being overridden in the three subclasses <strong>(Square, Circle, and Hexagon)<\/strong> of their base class or superclass <strong>Shape.<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Method-Overriding-in-Java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77078\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Method-Overriding-in-Java.jpg\" alt=\"Java Method Overriding\" width=\"661\" height=\"449\" \/><\/a><\/p>\n<h3>Example and Code to Understand Method Overriding in Java<\/h3>\n<p>Let\u2019s take a simple example to understand the concept of Method Overriding. We have two classes: A parent class Shape and a child class Circle. The Circle class inherits the Shape class.<\/p>\n<p>Both the classes have a common method void draw(). The child class is giving its own implementation to the draw() method. In other words, it is overriding the draw() method of the parent class.<\/p>\n<p>The purpose of Method Overriding is that if the derived class wants to give its own implementation it can give by overriding the method of the parent class. When we call this overridden method, it will execute the method of the child class, not the parent class.<\/p>\n<p>This example is illustrated below with the help of code.<\/p>\n<p><strong>Code to understand the concept of Method Overriding:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Base class\nclass Shape\n{\n  void draw()\n  {\n    System.out.println(\"Inside the method of Parent class \");\n    System.out.println(\"Drawing Shapes\");\n  }\n}\n\n\/\/Derived class\nclass Circle extends Shape\n{\n  \/\/Overriding method of base class with different implementation\n  @Override\n  void draw()\n  {\n    System.out.println(\"Inside the overridden method of the child class \");\n    System.out.println(\"Drawing Circle\");\n  }\n}\n\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    \/\/creating object of Base class Shape\n    \/\/ If a Parent type reference refers\n    \/\/ to a Parent object, then Parent's draw() method is called\n\n    Shape obj = new Shape();\n    obj.draw();\n\n    \/\/ If a Parent type reference refers to a Child object Child's draw() method is called.\n    \/\/This is called RUN TIME POLYMORPHISM.\n\n    Shape obj1=new Circle();\n    obj1.draw();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside the method of Parent class<br \/>\nDrawing Shapes<br \/>\nInside the overridden method of the child class<br \/>\nDrawing Circle<\/div>\n<h3>Rules for Method Overriding in Java<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/rules-for-method-overriding-in-java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77093\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/rules-for-method-overriding-in-java.jpg\" alt=\"Java Method Overriding Rules\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h4>1. Overriding Access-Modifiers<\/h4>\n<p>We can change the access modifier for an overriding method. In the derived class, while overriding a method, we can provide less restriction, but not more, restrictive access than the access of the overridden method of the superclass.<\/p>\n<p>For example, the method declared as public in the super-class cannot be made private or protected while overriding it in the subclass.<\/p>\n<p>Similarly, the protected method can be made public but not private in the subclass. If we provide lesser access in the subclass than that in the superclass, then we will get a compile-time error.<\/p>\n<p><em><strong>Dive a little deep into the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/access-modifiers-in-java\/\">Access Modifier in Java<\/a> with Techvidvan.<\/strong><\/em><\/p>\n<p><em><strong>Note:<\/strong> We cannot override private methods !!<\/em><\/p>\n<p><strong>Code to illustrate Method Overriding and Access Modifiers:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Parent Class\nclass ParentClass\n{\n  \/\/ private methods are not overridden\n  private void parentMethod1()\n  {\n    System.out.println(\"Inside the parentMethod1() of ParentClass\");\n  }\n\n  protected void parentMethod2()\n  {\n    System.out.println(\"Inside the parentMethod2() of ParentClass\");\n  }\n}\n\nclass ChildClass extends ParentClass\n{\n\n  private void parentMethod1()\n  {\n    System.out.println(\"Inside the parentMethod1() of ChildClass\");\n  }\n\n  \/\/ overriding method with more accessibility\n  @Override\n  public void parentMethod2()\n  {\n    System.out.println(\"Inside the parentMethod1() of ChildClass\");\n  }\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n\n    ParentClass obj1 = new ParentClass();\n    obj1.parentMethod1(); \/\/overriding private methods will give an error\n    obj1.parentMethod2();\n\n    ParentClass obj2 = new ChildClass();\n    obj2.parentMethod2();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Exception in thread &#8220;main&#8221; java.lang.Error: Unresolved compilation problem:<br \/>\nThe method parentMethod1() from the type ParentClass is not visible<br \/>\nat project1\/com.techvidvan.methodoverriding.MethodOverridingDeno.main(MethodOverridingDeno.java:39)<\/div>\n<p><strong>To remove the exception comment this line:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">obj1.parentMethod1();<\/pre>\n<p><strong>After commenting the above line we will get an output as:<\/strong><\/p>\n<div class=\"code-output\">Inside the parentMethod2() of ParentClass<br \/>\nInside the parentMethod1() of ChildClass<\/div>\n<h4>2. The methods declared as \u2018final\u2019 cannot be overridden<\/h4>\n<p>If we declare a method as final in the parent class then it can not be overridden in the subclass. It is used when we don\u2019t want other classes to override the methods in the wrong way.<\/p>\n<p><strong>Code Snippet to illustrate overriding of a final method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Base\n{\n      \t\/\/ final method can't be overridden\n      \tfinal void show()\n      \t{\n      \t}\n}\nclass Base extends Derived\n{\n      \t\/\/ This would produce an error\n      \tvoid show()\n      \t{\n      \t}\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">error: show() in Drived cannot override show() in Base<br \/>\nvoid show() { }<br \/>\n^<\/div>\n<p>An overridden method is final<\/p>\n<h4>3. The methods declared as \u2018static\u2019 cannot be overridden<\/h4>\n<p>Method hiding is the process of defining the static method in the derived class with the same signature as a static method in the base class.<\/p>\n<p>That is when you override a static method of the superclass with the static keyword, then it will hide the method of the superclass. If a derived class redefines the static method of the base class, then it does not override that method but hides it.<\/p>\n<p>The following table shows different scenarios when you define a method with the same signature as a method in a super-class.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Different-Scenarios-of-Method-Overriding-in-Java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77079\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Different-Scenarios-of-Method-Overriding-in-Java.jpg\" alt=\"Java Method Overriding Scenarios\" width=\"785\" height=\"424\" \/><\/a><\/p>\n<p><strong>Code to illustrate the overriding of a static method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Parent Class\nclass Parent\n{\nstatic void method1()\n{\n    System.out.println(\"Inside static method1() of Parent class\");\n}\nvoid method2()\n{\n    System.out.println(\"Inside non-static(instance) method2() of Parent class\");\n}\n}\nclass Child extends Parent\n{\n\/\/This will hide method1() of Child\nstatic void method1()\n{\n    System.out.println(\"Inside static method1() of child class\");\n}\n\/\/This method overrides method2() in Parent\n@Override\npublic void method2()\n{\n    System.out.println(\"Inside non-static(instance) method2() of child class\");\n}\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\npublic static void main(String args[])\n{\n    Parent obj2 = new Child();\n    obj2.method1();\n    obj2.method2();\n}\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside static method1() of Parent class<br \/>\nInside non-static(instance) method2() of child class<\/div>\n<p><strong>In the above code,<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">obj2.method1();<\/pre>\n<p>This statement should call method1 of child class but as the child class is overriding the method with the static keyword, therefore, this method will be hidden and the method1 of Parent class will be called.<\/p>\n<h4>4. Overriding Method must have the same return type (or subtype)<\/h4>\n<p>From Java 5.0 onwards, it is possible to have a different return type for an overridden method in the child class provided that the return type of child class be the same as a <strong>subtype<\/strong> of the overridden method&#8217;s <strong>return type of the base class.<\/strong> This type of return type is called a <strong>covariant return type.<\/strong><\/p>\n<p><strong>Code to illustrate the above concept:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Parent Class\nclass Parent\n{\n  Parent display(String sentence)\n  {\n    System.out.println(sentence);\n    return new Parent();\n  }\n}\n\/\/Child class\nclass Child extends Parent\n{\n  @Override\n  Child display(String sentence)\n  {\n    System.out.println(sentence);\n    return new Child();\n  }\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    Parent obj = new Child();\n    obj.display(\"TechVidvan's Java Tutorial\");\n    obj.display(\"Inside the method of the child class\");\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">TechVidvan&#8217;s Java Tutorial<br \/>\nInside the method of the child class<\/div>\n<h4>5. Invoking Overridden Methods from child class<\/h4>\n<p>We can invoke or call the method of parent class while overriding the method in the derived class using the <strong>super<\/strong> keyword.<\/p>\n<p><strong>Code to illustrate the use of super keyword for calling overridden methods:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Parent Class\nclass Parent\n{\n  void display()\n  {\n    System.out.println(\"Inside display() of Parent class\");\n  }\n}\n\n\/\/Child class\nclass Child extends Parent\n{\n  @Override\n  void display()\n  {\n\n    \/\/calling the parent class method through the super keyword\n    super.display();\n\n    System.out.println(\"Inside display() of child class\");\n  }\n}\n\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    Parent obj = new Child();\n    obj.display();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside display() of Parent class<br \/>\nInside display() of child class<\/div>\n<h4>6. Overriding Constructors<\/h4>\n<p>Constructors cannot be overridden that is the name of the constructors cannot be the same in parent and child class. Because the name of the constructor is always the same as the class name.<\/p>\n<h4>7. Overriding Abstract Methods<\/h4>\n<p>We can override Java Abstract methods only in the concrete classes, otherwise, a compile-time error will occur. A concrete class is a class that has the implementation of all of its methods. Simply, the classes that have no abstract methods are called concrete classes.<\/p>\n<h4>8. Overriding Methods from different packages<\/h4>\n<p>A <a href=\"https:\/\/www.ibm.com\/support\/knowledgecenter\/en\/SS6SG3_4.2.0\/com.ibm.entcobol.doc_4.2\/PGandLR\/tasks\/tpoot30.htm\">subclass<\/a> is present in a different package, then it can only override the <strong>non-final<\/strong> methods which are declared as<strong> public or protected.<\/strong><\/p>\n<h4>9. Overriding and Exception-Handling in Java<\/h4>\n<p>There are two rules that we should remember while handling exceptions in Java:<\/p>\n<p><strong>Rule 1:<\/strong><\/p>\n<p>When a checked expression is thrown, it causes a compile-time error. If the superclass doesn\u2019t throw any exception then the subclass can throw an error.<\/p>\n<p>The overriding method in the subclass can throw any unchecked (runtime) exception irrespective of whether the overridden method in the superclass declares the exception.<\/p>\n<p><strong>Code to explain Rule1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\nclass Parent\n{\n  void display1()\n  {\n    System.out.println(\"Inside display1() method of Parent class\");\n  }\n  void display2()\n  {\n    System.out.println(\"Inside display2() method of Parent class\");\n  }\n}\nclass Child extends Parent\n{\n  @Override\n  \/\/no issue while throwing unchecked exception\n  void display1() throws ArithmeticException\n  {\n    System.out.println(\"Inside display1() method of Child class\");\n  }\n  @Override\n  \/\/compile-time error\n  \/\/issue while throwing checked exception\n  void display2() throws Exception\n  {\n    System.out.println(\"Inside display2() method of Child class\");\n  }\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    Parent obj = new Child();\n    obj.display1();\n    obj.display2();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside display1() method of Child class<br \/>\nException in thread &#8220;main&#8221; java.lang.Error: Unresolved compilation problem:<br \/>\nException Exception is not compatible with throws clause in Parent.display2()at project1\/com.techvidvan.methodoverriding.Child.display2(MethodOverridingDemo.java:24)<br \/>\nat project1\/com.techvidvan.methodoverriding1.MethodOverridingDemo.main(MethodOverridingDemo.java:36)<\/div>\n<p><strong>Rule 2:<\/strong><\/p>\n<p>A compile-time error occurs if an exception occurs in a parent class. The overriding methods of the child class should not throw any checked exceptions that are broader or newer to the exceptions declared by the overridden methods of the parent class.<\/p>\n<p>For example, we can not override a method that declares an SQLException. Exception or any other non-runtime exception which is being overridden from a method that declares a FileNotFoundException, unless it is a subclass of FileNotFoundException.<\/p>\n<p><strong>Code to explain Rule2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Parent Class\nclass Parent\n{\n  void display() throws RuntimeException\n  {\n    System.out.println(\"Inside display() method of Parent class\");\n  }\n}\n\/\/Child class1\nclass Child1 extends Parent\n{\n  @Override\n  \/\/ no issue while throwing same exception\n  void display() throws RuntimeException\n\n  {\n    System.out.println(\"Inside display() method of Child1 class\");\n  }\n}\n\nclass Child2 extends Parent\n{\n  @Override\n  \/\/no issue while throwing subclass exception\n  void display() throws ArithmeticException\n  {\n    System.out.println(\"Inside display() method of Child2 class\");\n  }\n}\nclass Child3 extends Parent\n{\n  @Override\n  \/\/no issue while not throwing any exception\n  void display()\n  {\n    System.out.println(\"Inside display() method of Child3 class\");\n  }\n}\nclass Child4 extends Parent\n{\n  @Override\n  \/\/compile-time error\n  \/\/issue while throwing parent exception\n  void display() throws Exception\n  {\n    System.out.println(\"Inside display() method of Child4 class\");\n  }\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    Parent obj = new Child1();\n    obj.display();\n\n    obj = new Child2();\n    obj.display();\n\n    obj = new Child3();\n    obj.display();\n\n    obj = new Child4();\n    obj.display();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside display() method of Child1 class<br \/>\nInside display() method of Child2 class<br \/>\nInside display() method of Child3 class<br \/>\nException in thread &#8220;main&#8221; java.lang.Error: Unresolved compilation problem:<br \/>\nException Exception is not compatible with throws clause in Parent.display()<br \/>\nat project1\/com.techvidvan.methodoverriding.Child4.display(MethodOverridingDemo.<br \/>\njava:45)<br \/>\nat project1\/com.techvidvan.methodoverriding1.MethodOverridingDemo.main(MethodOverridingDemo.java:65)<\/div>\n<h4>10. Overriding a Synchronized\/Strictfp Method<\/h4>\n<p>There is no effect on the overridden method if the method in the superclass is declared as synchronized or strictfp.<\/p>\n<h3>Method Overriding in Multilevel Inheritance in Java<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.methodoverriding;\n\/\/Base Class\nclass Parent\n{\nvoid display()\n{\n  System.out.println(\"Inside display() method of Parent class\");\n}\n}\n\/\/Inherited class\nclass Child extends Parent\n{\n\/\/This method overrides show() of Parent\nvoid display()\n{\n  System.out.println(\"Inside display() method of Child class\");\n}\n}\n\/\/Inherited class\nclass GrandChild extends Child\n{\n\/\/This method overrides show() of Parent\nvoid display()\n{\n  System.out.println(\"Inside display() method of GrandChild class\");\n}\n}\n\/\/Driver class\npublic class MethodOverridingDemo\n{\n  public static void main(String args[])\n  {\n    Parent obj1 = new GrandChild();\n    obj1.display();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside display() method of GrandChild class<\/div>\n<h3>When to Apply Method Overriding in Java<\/h3>\n<p>Method Overriding is when a class has several derived classes and the derived classes need to use the methods of their parent class with the same signature <em>(number, type, and order of parameter)<\/em>, but with the different implementation.<\/p>\n<p>They can override the same method and add specific functionality without even disturbing the code of the parent class.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Example-of-Method-Overriding-in-Java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77081\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Example-of-Method-Overriding-in-Java.jpg\" alt=\"Example of Java Method Overriding\" width=\"806\" height=\"461\" \/><\/a><\/p>\n<p>From the above diagram, the Employee class defines a getSalary() method, which is inherited by both classes Programmer and SalesPerson. But, the SalesPerson class modifies the method by adding a bonus.<\/p>\n<h3>Summary<\/h3>\n<p>From this article, we can conclude that the subclass can give its own specific implementation or definition to the method which it overrides, without even modifying its parent class.<\/p>\n<p>We covered the detailed description of the runtime polymorphism with the help of Method Overriding in Java. We also discussed various rules which should be kept in mind while using Method Overriding in Java.<\/p>\n<p>Thank you for reading our article. Do share our article on Social Media.<\/p>\n<p>Happy Learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last tutorial, we have learned the concept of Polymorphism in Java. We covered the two kinds of polymorphism in Java and the process of implementing them in Java. We know that static&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77093,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[1868,1869,1870,1871,1872,1873,1874,1875,1876],"class_list":["post-76930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-function-override-in-java","tag-java-method-overridden","tag-java-method-overriding","tag-java-method-overriding-examples","tag-java-method-overriding-tutorial","tag-method-overriding-importance","tag-method-overriding-in-java","tag-method-overriding-rules-in-java","tag-override-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Method Overriding - Learn its Importance and Rules with Coding Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Get to know in detail about Java Method Overriding with its importance &amp; explore the rules of method Overriding in detail with the help of coding examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Method Overriding - Learn its Importance and Rules with Coding Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Get to know in detail about Java Method Overriding with its importance &amp; explore the rules of method Overriding in detail with the help of coding examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-28T08:40:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Method Overriding - Learn its Importance and Rules with Coding Examples - TechVidvan","description":"Get to know in detail about Java Method Overriding with its importance & explore the rules of method Overriding in detail with the help of coding examples.","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:\/\/techvidvan.com\/tutorials\/java-method-overriding\/","og_locale":"en_US","og_type":"article","og_title":"Java Method Overriding - Learn its Importance and Rules with Coding Examples - TechVidvan","og_description":"Get to know in detail about Java Method Overriding with its importance & explore the rules of method Overriding in detail with the help of coding examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-02-28T08:40:32+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Method Overriding &#8211; Learn its Importance and Rules with Coding Examples","datePublished":"2020-02-28T08:40:32+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/"},"wordCount":1702,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg","keywords":["Function Override in Java","Java Method Overridden","Java Method Overriding","Java Method Overriding Examples","Java Method Overriding Tutorial","Method Overriding Importance","Method Overriding in Java","Method Overriding rules in Java","Override Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/","url":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/","name":"Java Method Overriding - Learn its Importance and Rules with Coding Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg","datePublished":"2020-02-28T08:40:32+00:00","description":"Get to know in detail about Java Method Overriding with its importance & explore the rules of method Overriding in detail with the help of coding examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/rules-for-method-overriding-in-java.jpg","width":802,"height":420,"caption":"Java Method Overriding Rules"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-method-overriding\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Method Overriding &#8211; Learn its Importance and Rules with Coding Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/76930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=76930"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/76930\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77093"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=76930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=76930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=76930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}