Implementation of Java method overloading (changing the data types)
KW.java
classArea{staticintrectangle(inta,intb){returna*b;}staticdoublerectangle(doublea,doubleb){returna*b;}}classKW{publicstaticvoidmain(Stringargs[]){System.out.println("Area of Rectangle "+Area.rectangle(3.14,10.0));System.out.println("Area of Rectangle "+Area.rectangle(5,10));}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Area of Rectangle 31.400000000000002
Area of Rectangle 50
kodingwindow@kw:~$
Implementation of Java method overloading (changing the number of arguments)
KW.java
classArea{staticintrectangle(inta,intb){returna*b;}staticintrectangle(inta){returna*a;}}classKW{publicstaticvoidmain(Stringargs[]){//Every square is rectangleSystem.out.println("Area of Square "+Area.rectangle(5));System.out.println("Area of Rectangle "+Area.rectangle(5,10));}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Area of Square 25
Area of Rectangle 50
kodingwindow@kw:~$
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?