{"id":1528,"date":"2022-03-05T06:36:40","date_gmt":"2022-03-05T06:36:40","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1528"},"modified":"2022-03-05T06:36:40","modified_gmt":"2022-03-05T06:36:40","slug":"can-we-overload-the-methods-by-making-them-static","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/05\/can-we-overload-the-methods-by-making-them-static\/","title":{"rendered":"Can we overload the methods by making them static?"},"content":{"rendered":"\n<p>No, We cannot overload the methods by just applying the static keyword to them(number of parameters and types are the same). Consider the following example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Animal  \n{  \n    void consume(int a)  \n    {  \n        System.out.println(a+\" consumed!!\");  \n    }  \n    static void consume(int a)  \n    {  \n        System.out.println(\"consumed static \"+a);  \n    }  \n    public static void main (String args&#91;])  \n    {  \n        Animal a = new Animal();  \n        a.consume(10);  \n        Animal.consume(20);  \n    }  \n}    <\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Animal.java:7: error: method consume(int) is already defined in class Animal\n    static void consume(int a)\n                ^\nAnimal.java:15: error: non-static method consume(int) cannot be referenced from a static context\n        Animal.consume(20);\n              ^\n2 errors<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>No, We cannot overload the methods by just applying the static keyword to them(number of parameters and types are the same). Consider the following example. Output<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[559],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1528"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1528"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1528\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}