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

Other Lessons for You

Introductory discussions on Complexity Analysis
What is Complexity Analysis of Algorithm? Complexity Analysis, simply put, is a technique through which you can judge about how good one particular algorithm is. Now the term “good” can...

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

Living with Concepts
Always it is a complain from many students that they do not remember concepts taught and learnt as time progresses. Even exceptional students also falls pray to effect of time fading. The tip which i generally...
B

Babu T

0 0
0

A note on working of Transmission Control Protocol in Computer Networks.
TCP Connection establishment and termination TCP is one of theTCP is connection oriented protocol and reliable protocol. It originated in the initial network implementation in which it complemented the...

Standard Algorithms
Standard algorithms serve as good solutions to standard problems. These algorithms, many of which are intertwined with data structures, provide excellent examples for the analysis of program efficiency....
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