{"id":155683,"date":"2023-12-17T14:04:00","date_gmt":"2023-12-17T14:04:00","guid":{"rendered":"https:\/\/www.henryharvin.com\/blog\/?p=155683"},"modified":"2024-12-23T10:16:58","modified_gmt":"2024-12-23T10:16:58","slug":"method-overloading-in-java","status":"publish","type":"post","link":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/","title":{"rendered":"Method Overloading in Java with Examples: 202"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Function_overloading\" target=\"_blank\" rel=\"noreferrer noopener\">Method Overloading<\/a> is an essential concept in Java. It helps to increase the program&#8217;s readability.&nbsp; Programmers can reduce the execution time and make the coding looks clean. Moreover, it provides flexibility. Let&#8217;s discuss in detail <strong>Method Overloading in Java with Example<\/strong>.<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"940\" height=\"788\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24154854\/Method-Overloading.png\" alt=\"Method Overloading in java\" class=\"wp-image-155739\" srcset=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24154854\/Method-Overloading.png 940w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24154854\/Method-Overloading-300x251.png 300w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24154854\/Method-Overloading-768x644.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method Overloading in Java<\/strong><\/h2>\n\n\n\n<p>In the same class, if we have many methods of the same name is called method overloading. However, it differs in the Number of arguments and type of arguments.<\/p>\n\n\n\n<p>Suppose, You want to add a given number. But the Number can be anything. In the case of adding two numbers, then<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a(int a, int b)\n{\n int c;\n c=a+b;\n return c;\n}\n<\/code><\/pre>\n\n\n\n<p>If you wish to add three integers, then<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int b(int a, int b, int c)\n{\n  int d;\n  d=a+b+c;\n  return d;\n}\n<\/code><\/pre>\n\n\n\n<p>b(int, int, int). While doing as above will create confusion.&nbsp;<\/p>\n\n\n\n<p>The operation&#8217;s name differs from its behavior, and the programmers need clarification. Overloading takes the place of solving the problem mentioned above. Therefore, Method Overloading increases the readability of the program.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int add(int a, int b)\n{\n int c;\n c=a+b;\n return c;\n}\nint add(int a, int b, int c)\n{\n  int d;\n  d=a+b+c;\n  return d;\n}\n<\/code><\/pre>\n\n\n\n<p>Two approaches in this illustration share the same name, &#8220;add,&#8221; but the number of arguments differs. It is how Method Overloading works.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Java Full Stack Job Guarantee Program | Online Java Full Stack Developer Courser | Henry Harvin\" width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/TZVc0mdOHbw?start=63&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Types of method overloading in Java<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Overloading a method by having a different number of arguments<\/li><li>Overloading a method by having different datatypes of the arguments.<ol><li>By Overloading a method by changing the order of arguments.<\/li><\/ol><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1.Overloading a method by having a different number of arguments<\/strong><\/h2>\n\n\n\n<p>It is one type of method overloading in Java. You can have two methods having the same name, but it differs by the Number of parameters they have.<\/p>\n\n\n\n<p>Let&#8217;s see an example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Addition{  \nstatic int add(int a,int b)\n{\nreturn a+b;\n}  \nstatic int add(int a,int b,int c)\n{\nreturn a+b+c;\n}  \n}  \nclass OverloadingType1{  \npublic static void main(String&#091;] args){  \nSystem.out.println(Addition.add(11,11));  \nSystem.out.println(Addition.add(11,11,11));  \n}\n}  \n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">22<br>33<\/h4>\n\n\n\n<p>Here, the class name is Addition. We have two methods with the same name as add in the same class. But the difference is in the first method, the number of parameters is 2. At the same time, the second method has three parameters.<\/p>\n\n\n\n<p>In the main method, when the first statement executes, the control will go to the add method having two parameters. Similarly, when the second statement executes, control will go to the add method having 3&nbsp; parameters.&nbsp;<\/p>\n\n\n\n<p>So, that is how the method overloading in Java with type 1 works<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Overloading a method by having different datatype of the arguments<\/strong><\/h2>\n\n\n\n<p>It is one type of method overloading in Java. You can have two methods having the same name, but it differs in the type of parameters they have.<\/p>\n\n\n\n<p>Let&#8217;s see an example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Addition{  \nstatic int add(int a, int b)\n{\nreturn a+b;\n}  \nstatic double add(double a, double b)\n{\nreturn a+b;\n}  \n}  \nclass OverloadingType2{  \npublic static void main(String&#091;] args){  \nSystem.out.println(Addition.add(11,11));  \nSystem.out.println(Addition.add(12.3,12.6));  \n}\n}  \n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<p>22<br>24.9<\/p>\n\n\n\n<p>Here, the class name is Addition. We have two methods with the same name as add in the same class. But the difference is in the first method. The type of parameter is an integer. At the same time, the second method has a double type.<br><\/p>\n\n\n\n<p>In the main method, when the first statement executes, the control will go to the add method integer datatype. Similarly, when the second statement executes, control will go to the add method having datatype double. So, that is how the method overloading in Java with type 2 works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Overloading a method by changing the order of arguments<\/strong><\/h2>\n\n\n\n<p>For instance, if method 1&#8217;s arguments are (String name, int roll no) and method 2&#8217;s parameters are (int roll no, String name). Still, both methods have the same name, and then these two methods are seen to be overloaded with various parameter combinations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class StudentDetails{  \n    public void student(String name, int rollno)\n    {\n            System.out.println(\"Name :\" + name + \" \" + \"Roll No :\" + rollno);\n    }\n    public void student(int rollno, String name)\n    {\n        System.out.println(\"RollNo :\" + rollno + \" \" + \"Name :\" + name);\n    }\n}  \nclass OverloadingType3{  \npublic static void main(String&#091;] args){  \nStudentDetails obj = new StudentDetails();\nobj.student(\"Sakthi\", 1);\nobj.student(2, \"Nivetha\");\n}\n}  \n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Name: Sakthi Roll No :1<\/p>\n\n\n\n<p>Roll No:2 Name: Nivetha<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"940\" height=\"788\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24161754\/Palm-Sunday-1.png\" alt=\"method overloading in java\" class=\"wp-image-155742\" srcset=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24161754\/Palm-Sunday-1.png 940w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24161754\/Palm-Sunday-1-300x251.png 300w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24161754\/Palm-Sunday-1-768x644.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What happens if the accurate prototype conflicts with the arguments?<\/strong><\/h3>\n\n\n\n<p>Before going to the answer to this question, we should learn a little about type conversion in Java. Let&#8217;s check with type conversion.Like other languages, Java has a variety of data types.<br><br>They are boolean, char, int, unsigned int, signed int, float, double, and long. Hence, for seven types, each of which requires a different amount of memory space to store.<br><\/p>\n\n\n\n<p>The two data types may not be compatible when you assign one value to the other. The data types should be compatible with Java to convert them automatically. It is known as Automatic Type Conversion.<br><br>Otherwise, they must be cast or explicitly converted, like Putting an int value into a long variable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>DatatypeBits Acquired In Memory<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Datatype<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>size<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">boolean<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">byte<\/td><td class=\"has-text-align-center\" data-align=\"center\">8 (1 byte)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">char<\/td><td class=\"has-text-align-center\" data-align=\"center\">16 (2 bytes)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">short<\/td><td class=\"has-text-align-center\" data-align=\"center\">16 (2 byte)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">int<\/td><td class=\"has-text-align-center\" data-align=\"center\">32 (4 bytes)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">long<\/td><td class=\"has-text-align-center\" data-align=\"center\">64 (8 bytes)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">float<\/td><td class=\"has-text-align-center\" data-align=\"center\">32 (4 bytes)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">double<\/td><td class=\"has-text-align-center\" data-align=\"center\">64 (8 bytes)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Automatic conversion takes place in two ways. They are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Data types should be compatible.<\/li><li>A smaller data type&#8217;s value is transferred to a larger data type.<br><\/li><\/ul>\n\n\n\n<p>For instance, while Java&#8217;sJava&#8217;s numeric data types are compatible, automated translation to char or boolean is not supported. Moreover, char and boolean are incompatible.<\/p>\n\n\n\n<p><strong>Byte Short Int Long Float Double<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>class AutoConversion{\npublic static void main(String&#091;] args)\n    {\n        int i = 100;\n        long l = i;\nfloat f = l;\n\tSystem.out.println(\"Int value \" + i);\n        System.out.println(\"Long value \" + l);\n        System.out.println(\"Float value \" + f);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Int value 100<\/p>\n\n\n\n<p>Long value 100<\/p>\n\n\n\n<p>Float value 100.0<\/p>\n\n\n\n<p>Let&#8217;s now come to the answer, as mentioned earlier.<br><\/p>\n\n\n\n<p>The compiler does the following in order of priority:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Type conversion, but to a higher type within the same family (in terms of range).<\/li><li>Changing a type to the following higher family<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class Example{\n    public void show(int x)\n    {\n        System.out.println(\"In int\" + x);\n    }\n    public void show(String s)\n    {\n        System.out.println(\"In String\" + s);\n    }\n    public void show(byte b)\n    {\n        System.out.println(\"In byte\" + b);\n    }\n}\nclass ExampleMain {\n    public static void main(String&#091;] args)\n    {\n        byte a = 25;\n        Example e = new Example();\n  \n         e.show(a);\n         e.show(\"hello\");\n \t e.show(250);\n \t e.show('A');\n \t e.show(\"A\");\n \t e.show(7.5);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Exceptions in Method Overloading in Java<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>We cannot overload a method by changing its return type<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Top 10 Java Course in India | ReviewsReporter\" width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/qikO5mi4Ows?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Because of ambiguity, method overloading in Java is impossible by modifying the method&#8217;s return type. Let&#8217;s look at some examples of ambiguity.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Addition{  \nstatic int add(int a,int b)\n{\nreturn a+b;\n}  \nstatic double add(int a,int b)\n{\nreturn a+b;\n}  \n}  \nclass OverloadingType4{  \npublic static void main(String&#091;] args){  \nSystem.out.println(Adder.add(11,11));\/\/ambiguity  \n}\n}  \n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Compile Time Error<\/p>\n\n\n\n<p><strong>Note: <\/strong>Run Time Error is preferable to Compile Time Error. So, if you declare the same method with the same parameters, the Java compiler generates a compile time error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>We cannot overload the main() method in Java<\/strong><\/h3>\n\n\n\n<p>Through method overloading, yes. You can have many main methods. Yet, JVM invokes the main() function, which takes a string array as its single parameter. Here&#8217;s a clear illustration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class OverloadingType5{  \npublic static void main(String&#091;] args)\n{\nSystem.out.println(\"main with String&#091;]\");\n}  \npublic static void main(String args)\n{\nSystem.out.println(\"main with String\");\n}  \npublic static void main()\n{\nSystem.out.println(\"main without args\");\n}  \n}  \n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>main with String[]<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Can we Overload static methods in Java?<\/strong><\/h3>\n\n\n\n<p>The solution is &#8220;Yes.&#8221; Although they may have different input arguments, more than one static method with the same name are possible. Take the following<strong> <\/strong>Java program, for instance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class StaticMethodExample {\n    public static void disp() {\n        System.out.println(\"StaticMethodExample .disp() called \");\n    }\n    public static void disp(int a) {\n        System.out.println(\"StaticMethodExample .disp(int) called \");\n    }\n    public static void main(String args&#091;])\n    {\n        StaticMethodExample .disp();\n        StaticMethodExample .disp(10);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>StaticMethodExample .disp() called&nbsp;<\/p>\n\n\n\n<p>StaticMethodExample .disp(int) called<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"940\" height=\"788\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24155940\/Palm-Sunday.png\" alt=\"\" class=\"wp-image-155740\" srcset=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24155940\/Palm-Sunday.png 940w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24155940\/Palm-Sunday-300x251.png 300w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24155940\/Palm-Sunday-768x644.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Can a method be overloaded when it differs only by static keywords?<\/strong><\/h3>\n\n\n\n<p>If the two methods only differ by the static keyword, we cannot overload them if the number of parameters and types of parameters is the same.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ExampleStaticMethod{\n    public static void disp() {\n        System.out.println(\"ExampleStaticMethod.disp() called \");\n    }\n    public void disp() { \/\/ Compiler Error: cannot redefine foo()\n        System.out.println(\"ExampleStaticMethod.disp(int) called \");\n    }\n    public static void main(String args&#091;]) {\n        ExampleStaticMethod.disp();\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Compiler Error, cannot redefine disp()<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Advantages of method overloading<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Method overloading makes the code easier to read.<\/li><li>It makes our task much more straightforward by preventing us from having to memorize any exact names for the different types and numbers of parameters.<\/li><li>Method overloading makes it simpler to maintain the application.<\/li><li>For handling class objects, we can make effective use of overloaded methods.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method Overloading in Java with Example<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Find the Area of the Rectangle Using Method Overloading in Java<\/strong><\/h3>\n\n\n\n<p>The rectangle&#8217;s Area is calculated by multiplying its length by width or breadth. The following formula can be used to determine the rectangle&#8217;s Area quickly:<\/p>\n\n\n\n<p>rectangle Area = Length * Breath<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.*;\n \nclass RectangleArea {\n \n    void Area(double l, double b)\n    {\n        System.out.println(\"Area of the rectangle: \"\n                           + l * b);\n    }\n \n    void Area(int l, int b)\n    {\n        System.out.println(\"Area of the rectangle: \"\n                           + l * b);\n    }\n}\n \nclass MethodOverloadingExample{\n \npublic static void main(String&#091;] args)\n    {\n \n       RectangleArea r= new RectangleArea();\n \n        \/\/ Calling function\n        r.Area(20, 10);\n        r.Area(10.5, 5.5);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Area of the rectangle: 200<\/p>\n\n\n\n<p>Area of the rectangle: 57.75<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Find the Area of the circle Using the Method Overloading in Java<\/strong><\/h3>\n\n\n\n<p>The Area of the circle is the square of the circle&#8217;s radius multiplied by PI&#8217;s value. The following formula can be used to determine the circle&#8217;s surface area quickly:<\/p>\n\n\n\n<p>&nbsp;circle Area: A = \u03c0 * rad2<\/p>\n\n\n\n<p>where rad is the radius<\/p>\n\n\n\n<p>circle Area: A = (\u03c0 \/ 4) * dia2<\/p>\n\n\n\n<p>where dia is the diameter<\/p>\n\n\n\n<p>&nbsp;PI = 3.141592653589793.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 1:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.*;\n class CircleArea {\n static final double PI = Math.PI;\n   void Area(double rad)\n    {\n        double A = PI * rad * rad;\n        System.out.println(\"Circle area  is:\" + A);\n    }\n  void Area(float rad)\n    {\n        double A = PI * rad * rad;\n        System.out.println(\"Circle Area is:\" + A);\n    }\n}\n class MethodOverloadingExample\n{\n  public static void main(String&#091;] args)\n    {\n  CircleArea c= new CircleArea();\n  c.Area(5);\n  c.Area(2.5);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Circle Area is:78.53981633974483<\/p>\n\n\n\n<p>Circle Area is:19.634954084936208<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 2:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.*;\n class CircleArea {\n static final double PI = Math.PI;\n  void Area(double D)\n    {\n        double A = (PI \/ 4) * D * D;\nSystem.out.println(\"The area of the circle is:\" + A);\n    }\n \n    void Area(float D)\n    {\n        double A = (PI \/ 4) * D * D;\n   System.out.println(\"The area of the circle is:\" + A);\n    }\n}\n \nclass MethodOverloadingExample{\n \n       public static void main(String&#091;] args)\n    {\n   CircleArea c= new CircleArea();\n   c.Area(10);\n        c.Area(20.4);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>The Area of the circle is:78.53981633974483<\/p>\n\n\n\n<p>The Area of the circle is:326.851299679482<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"788\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24162251\/Palm-Sunday-2.png\" alt=\"\" class=\"wp-image-155743\" srcset=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24162251\/Palm-Sunday-2.png 940w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24162251\/Palm-Sunday-2-300x251.png 300w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/24162251\/Palm-Sunday-2-768x644.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Find the Area of the Square Using the Method Overloading in Java<\/strong><\/h3>\n\n\n\n<p>The square&#8217;s Area equals the sum of its sides. The following formula can be used to determine the square&#8217;s Area quickly:<\/p>\n\n\n\n<p>Area of the Square: A = s2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.*;\n class SquareArea {\n     void Area(double side)\n    {\n        System.out.println(\"Area of the Square: \"\n                           + side * side);\n    }\n   void Area(float side)\n    {\n        System.out.println(\"Area of the Square: \"\n                           + side * side);\n    }\n}\n \nclass MethodOverloadingExample{\n     public static void main(String&#091;] args)\n    {\n         SquareArea s= new SquareArea();\n         s.Area(10);\n         s.Area(3.2);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Area of the Square: 100.0<\/p>\n\n\n\n<p>Area of the Square: 10.240000000000002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Print Different Types of Array using method overloading in Java<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class methodOverloadingDemo {\n    public static void printArray(Integer&#091;] arr)\n    {\n        System.out.println(\"\\nThe Integer array is: \");\n     for (Integer i : arr)\n            System.out.print(i + \" \");\n        System.out.println();\n    }\n \n   public static void printArray(Character&#091;] arr)\n    {\n        System.out.println(\"\\nThe Character array is: \");\n \n     for (Character i : arr)\n            System.out.print(i + \" \");\n        System.out.println();\n    }\n \n    public static void printArray(String&#091;] arr)\n    {\n        System.out.println(\"\\nThe String array is: \");\n \n        for (String i : arr)\n            System.out.print(i + \" \");\n        System.out.println();\n    }\n \n    public static void printArray(Double&#091;] arr)\n    {\n        System.out.println(\"\\nThe Double array is: \");\n \n            for (Double i : arr)\n            System.out.print(i + \" \");\n    }\n \n    public static void main(String args&#091;])\n    {\n Integer&#091;] iarr = { 2, 12, 22, 32, 42 };\n        Character&#091;] carr = { 'W', 'E', 'L', 'C', 'O', 'M', 'E' };\n        String&#091;] sarr\n            = { \"Nivetha\", \"Iniya\", \"Sakthi\", \"Siva\", \"Madhu\" };\n        Double&#091;] darr\n            = { 42.3210, 91.321, 75.231, 28.543, 5.342 };\n \n        printArray(iarr);\n        printArray(carr);\n        printArray(sarr);\n        printArray(darr);\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>The Integer array is:&nbsp;<\/p>\n\n\n\n<p>2 12 22 32 42<\/p>\n\n\n\n<p>The Character array is:&nbsp;<\/p>\n\n\n\n<p>W E L C O M E<\/p>\n\n\n\n<p>The String array is:&nbsp;<\/p>\n\n\n\n<p>Nivetha Iniya Sakthi Siva Madhu<\/p>\n\n\n\n<p>The Double array is:&nbsp;<\/p>\n\n\n\n<p>42.3210 91.321 75.231 28.543 5.342&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Java Tutorial: Method Overloading in Java\" width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/pFaB68naMiU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Online Java Training<\/strong><\/h2>\n\n\n\n<p>Henry Harvin offers the JAVA Foundation the DS &amp; Algo Combo Certification Course, which BestCourseNews.com has named the best Java certification course. With this course, which more than 160 top corporations endorse, you will be recognized as a Certified Java Developer and receive hands-on instruction with more than 350 coding challenges and 50+ Java tools. The website of Henry Harvin has more information on this program right now.<\/p>\n\n\n\n<p><strong>Henry Harvin provides Java Courses by professionals. Enroll now to learn more about Java<\/strong> <a href=\"https:\/\/www.henryharvin.com\/java-programming-for-beginners\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java Programming Course for Beginners<\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Recommended Reads<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/www.henryharvin.com\/blog\/essential-java-full-stack-developer-skills\/\"><strong>Java Full Stack Developer Skills in 2023<\/strong><\/a><\/li><li><a href=\"https:\/\/www.henryharvin.com\/blog\/core-java-interview-questions-and-answers\/\"><strong>40+ Core Java Interview Questions and Answers for Freshers and Experienced in 2023<\/strong><\/a><\/li><li><a href=\"https:\/\/www.henryharvin.com\/blog\/java-books\/\"><strong>Top 20 Java Books for 2023<\/strong><\/a><\/li><li><a href=\"https:\/\/www.henryharvin.com\/blog\/oops-interview-questions-and-answers\/\"><strong>Top 50+ OOPs Interview Questions and Answers in 2023<\/strong><\/a><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">FAQS<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1679648745696\"><strong class=\"schema-faq-question\"><strong>1. What is method overloading in Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">Method overloading is when the methods&#8217; names are the same, but their parameters vary.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648762827\"><strong class=\"schema-faq-question\"><strong>2. In Java, can static methods be overloaded?<\/strong><\/strong> <p class=\"schema-faq-answer\">Sure, static methods in Java can be overloaded, but they cannot be replaced.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648782211\"><strong class=\"schema-faq-question\"><strong>3. Can the main method be overloaded?<\/strong><\/strong> <p class=\"schema-faq-answer\">Indeed, you can overload the main method in Java, but the JVM will only call the method with the signature public static void main(String[] args)<strong>.<\/strong><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648802178\"><strong class=\"schema-faq-question\">4. <strong>Can we alter the method overloading&#8217;s return type only?<\/strong><\/strong> <p class=\"schema-faq-answer\">No, If we merely alter the return type, the compiler will have trouble determining which method to call.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648826042\"><strong class=\"schema-faq-question\">5. <strong>Describe the method signature. What components does it have?<\/strong><\/strong> <p class=\"schema-faq-answer\">The compiler uses the method signature to distinguish between the methods. There are three components to a method signature. They are the method&#8217;s name, Number of arguments, and Argument types.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648853498\"><strong class=\"schema-faq-question\">6. <strong>Can methods that are overloaded be synchronized?<\/strong><\/strong> <p class=\"schema-faq-answer\">Yes. Methods that are overloaded can be synchronized.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679648856024\"><strong class=\"schema-faq-question\"><strong>7. Is it possible to make overloaded methods final?<\/strong><\/strong> <p class=\"schema-faq-answer\">Indeed, overloaded methods may be declared final.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Method Overloading is an essential concept in Java. It helps to increase the program&#8217;s readability.&nbsp; Programmers can reduce the execution&#8230;<\/p>\n","protected":false},"author":952,"featured_media":156312,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","two_page_speed":[],"footnotes":""},"categories":[18655],"tags":[],"class_list":["post-155683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Method Overloading in Java with Examples: 2024<\/title>\n<meta name=\"description\" content=\"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions\" \/>\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.henryharvin.com\/blog\/method-overloading-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Method Overloading in Java with Examples: 2024\" \/>\n<meta property=\"og:description\" content=\"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Henry Harvin Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-17T14:04:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-23T10:16:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"1067\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nivetha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@henryharvin_in\" \/>\n<meta name=\"twitter:site\" content=\"@henryharvin_in\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nivetha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/\"},\"author\":{\"name\":\"Nivetha\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/6581e2923d5784de9f69dd5e6886667d\"},\"headline\":\"Method Overloading in Java with Examples: 202\",\"datePublished\":\"2023-12-17T14:04:00+00:00\",\"dateModified\":\"2024-12-23T10:16:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/\"},\"wordCount\":1596,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\"},\"image\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/31064421\\\/pasted-image-0-2023-03-31T121405.458.jpg\",\"articleSection\":[\"Java Blogs | Learn More About Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/\",\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/\",\"name\":\"Method Overloading in Java with Examples: 2024\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/31064421\\\/pasted-image-0-2023-03-31T121405.458.jpg\",\"datePublished\":\"2023-12-17T14:04:00+00:00\",\"dateModified\":\"2024-12-23T10:16:58+00:00\",\"description\":\"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648745696\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648762827\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648782211\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648802178\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648826042\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648853498\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648856024\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/31064421\\\/pasted-image-0-2023-03-31T121405.458.jpg\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/31064421\\\/pasted-image-0-2023-03-31T121405.458.jpg\",\"width\":1600,\"height\":1067},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Blogs | Learn More About Java\",\"item\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/category\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Method Overloading in Java with Examples: 202\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/\",\"name\":\"Henry Harvin Blog\",\"description\":\"Latest Online Courses &amp; Certification Blogs\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\",\"name\":\"George L V\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"width\":445,\"height\":130,\"caption\":\"George L V\"},\"logo\":{\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\"},\"description\":\"George is an expert communicator. As a coordinator, senior language instructor, center head and a content writer the basic requirement at the DNA level was the same \u2013 effective communication. He discovered early in life that quality of communication makes the difference between great results and mediocre outcomes. And thus, he developed his first forte: focus on the listener and tailor the message accordingly. As he progressed in his career, he realized that the most compelling stories communicate through multi-sensory messaging - a powerful combination of visual, verbal, and intuitive content.\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/6581e2923d5784de9f69dd5e6886667d\",\"name\":\"Nivetha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/07070920\\\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/07070920\\\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/07070920\\\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg\",\"caption\":\"Nivetha\"},\"description\":\"I am Nivetha. I am a Former Android Developer. My desire to write led me to begin a career in content writing. Now I am improving my writing skills in Henry Harvin as a Guest Writer.\",\"sameAs\":[\"https:\\\/\\\/www.henryharvin.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/author\\\/nivethasakthikumarangmail-com\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648745696\",\"position\":1,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648745696\",\"name\":\"1. What is method overloading in Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Method overloading is when the methods' names are the same, but their parameters vary.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648762827\",\"position\":2,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648762827\",\"name\":\"2. In Java, can static methods be overloaded?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Sure, static methods in Java can be overloaded, but they cannot be replaced.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648782211\",\"position\":3,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648782211\",\"name\":\"3. Can the main method be overloaded?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Indeed, you can overload the main method in Java, but the JVM will only call the method with the signature public static void main(String[] args)<strong>.<\\\/strong>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648802178\",\"position\":4,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648802178\",\"name\":\"4. Can we alter the method overloading's return type only?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No, If we merely alter the return type, the compiler will have trouble determining which method to call.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648826042\",\"position\":5,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648826042\",\"name\":\"5. Describe the method signature. What components does it have?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The compiler uses the method signature to distinguish between the methods. There are three components to a method signature. They are the method's name, Number of arguments, and Argument types.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648853498\",\"position\":6,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648853498\",\"name\":\"6. Can methods that are overloaded be synchronized?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. Methods that are overloaded can be synchronized.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648856024\",\"position\":7,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/method-overloading-in-java\\\/#faq-question-1679648856024\",\"name\":\"7. Is it possible to make overloaded methods final?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Indeed, overloaded methods may be declared final.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Method Overloading in Java with Examples: 2024","description":"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions","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.henryharvin.com\/blog\/method-overloading-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Method Overloading in Java with Examples: 2024","og_description":"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions","og_url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/","og_site_name":"Henry Harvin Blog","article_published_time":"2023-12-17T14:04:00+00:00","article_modified_time":"2024-12-23T10:16:58+00:00","og_image":[{"width":1600,"height":1067,"url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg","type":"image\/jpeg"}],"author":"Nivetha","twitter_card":"summary_large_image","twitter_creator":"@henryharvin_in","twitter_site":"@henryharvin_in","twitter_misc":{"Written by":"Nivetha","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#article","isPartOf":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/"},"author":{"name":"Nivetha","@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/6581e2923d5784de9f69dd5e6886667d"},"headline":"Method Overloading in Java with Examples: 202","datePublished":"2023-12-17T14:04:00+00:00","dateModified":"2024-12-23T10:16:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/"},"wordCount":1596,"commentCount":0,"publisher":{"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094"},"image":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg","articleSection":["Java Blogs | Learn More About Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/","url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/","name":"Method Overloading in Java with Examples: 2024","isPartOf":{"@id":"https:\/\/www.henryharvin.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg","datePublished":"2023-12-17T14:04:00+00:00","dateModified":"2024-12-23T10:16:58+00:00","description":"In this blog Method Overloading in Java is explained in detail with examples, outputs, and frequently asked interview questions","breadcrumb":{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648745696"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648762827"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648782211"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648802178"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648826042"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648853498"},{"@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648856024"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#primaryimage","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/31064421\/pasted-image-0-2023-03-31T121405.458.jpg","width":1600,"height":1067},{"@type":"BreadcrumbList","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.henryharvin.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java Blogs | Learn More About Java","item":"https:\/\/www.henryharvin.com\/blog\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Method Overloading in Java with Examples: 202"}]},{"@type":"WebSite","@id":"https:\/\/www.henryharvin.com\/blog\/#website","url":"https:\/\/www.henryharvin.com\/blog\/","name":"Henry Harvin Blog","description":"Latest Online Courses &amp; Certification Blogs","publisher":{"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.henryharvin.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094","name":"George L V","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","width":445,"height":130,"caption":"George L V"},"logo":{"@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png"},"description":"George is an expert communicator. As a coordinator, senior language instructor, center head and a content writer the basic requirement at the DNA level was the same \u2013 effective communication. He discovered early in life that quality of communication makes the difference between great results and mediocre outcomes. And thus, he developed his first forte: focus on the listener and tailor the message accordingly. As he progressed in his career, he realized that the most compelling stories communicate through multi-sensory messaging - a powerful combination of visual, verbal, and intuitive content."},{"@type":"Person","@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/6581e2923d5784de9f69dd5e6886667d","name":"Nivetha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/07070920\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/07070920\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/07070920\/WhatsApp-Image-2023-03-06-at-18.31.56-150x150.jpeg","caption":"Nivetha"},"description":"I am Nivetha. I am a Former Android Developer. My desire to write led me to begin a career in content writing. Now I am improving my writing skills in Henry Harvin as a Guest Writer.","sameAs":["https:\/\/www.henryharvin.com\/blog"],"url":"https:\/\/www.henryharvin.com\/blog\/author\/nivethasakthikumarangmail-com\/"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648745696","position":1,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648745696","name":"1. What is method overloading in Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Method overloading is when the methods' names are the same, but their parameters vary.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648762827","position":2,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648762827","name":"2. In Java, can static methods be overloaded?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Sure, static methods in Java can be overloaded, but they cannot be replaced.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648782211","position":3,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648782211","name":"3. Can the main method be overloaded?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Indeed, you can overload the main method in Java, but the JVM will only call the method with the signature public static void main(String[] args)<strong>.<\/strong>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648802178","position":4,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648802178","name":"4. Can we alter the method overloading's return type only?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No, If we merely alter the return type, the compiler will have trouble determining which method to call.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648826042","position":5,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648826042","name":"5. Describe the method signature. What components does it have?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The compiler uses the method signature to distinguish between the methods. There are three components to a method signature. They are the method's name, Number of arguments, and Argument types.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648853498","position":6,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648853498","name":"6. Can methods that are overloaded be synchronized?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. Methods that are overloaded can be synchronized.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648856024","position":7,"url":"https:\/\/www.henryharvin.com\/blog\/method-overloading-in-java\/#faq-question-1679648856024","name":"7. Is it possible to make overloaded methods final?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Indeed, overloaded methods may be declared final.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"views":1856,"_links":{"self":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts\/155683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/users\/952"}],"replies":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/comments?post=155683"}],"version-history":[{"count":3,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts\/155683\/revisions"}],"predecessor-version":[{"id":228717,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts\/155683\/revisions\/228717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/media\/156312"}],"wp:attachment":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/media?parent=155683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/categories?post=155683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/tags?post=155683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}