UrbanPro
true

Take BTech Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Overloading in JAVA

Swati S.
19/05/2020 0 0

When a class contains more than one method with the same method name but different argument types, then it is called Overloading.

Methods are said to be Overloaded methods.

Also, know as Compile time binding or Early binding.

The compiler takes care of overloaded methods and decides according to the signature which way is to be invoked.

Eg:    class Display

         {

        public void show( int b) //1

         {System.out.println(b);}

        public void  show(String s) //2

        {System.out.println(s);}

          public static void main(String args[ ])

          {

        Display d = new Display();

        d.show(2);//1 method invoked

        d.show("Swati");//2 method invoked

       d.show( 10.5f)/*in 3 invocation

    1  method gets invoked though show(float ) not present*/

}

}

1 &2  are overloaded methods in class Display.During a method call compiler first searches for exactly matched method calls in class.3 invocation  compiler actually searches for show(float f)  but it is not found.So it again searches for the method having argument that can be promoted into float and encounters 1 method.As we all know int can be converted into float.This is called Automatic argument promotion.

 

 

Output of program

Swati

10.5

0 Dislike
Follow 2

Please Enter a comment

Submit

X

Looking for BTech Tuition Classes?

The best tutors for BTech Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BTech Tuition with the Best Tutors

The best Tutors for BTech Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more