true

Find the best tutors and institutes for BTech Tuition

Find Best BTech Tuition

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Overloading in JAVA

Swati S.
19 May 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


Estimation of Water and Wastewater Flow
Before designing the proper waterworks project, it is essential to determine the quantity of water that is required daily. This involves the determination of the population and the rate of demand. The...

Sandip Nandi | 28 May

0 0
0

What Are the Factors Affecting the Compaction of Soil?
The various factors which affect the compaction of soil are as follows: Moisture content. To achieve the desired density of the soil, the moisture content of that soil has to be controlled properly. Types...

Phani J V | 07 Apr

0 0
0

What are the assumptions made in the analysis of struts and columns by Eulers buckling theory?
The assumptions made in the analysis of columns and struts by Euler’s theory are: The column that is being analyzed has a uniform cross section throughout its length. The column is initially...

Phani J V | 05 Apr

0 0
0

what is elementary profile of gravity dam?
A Gravity dam is a structure which is designed in such a way that its own weight resist the external forces acting on it like Water pressure, pressure due to uplift , waves and silt. If you look...

Phani J V | 05 Apr

0 0
0
X

Looking for BTech Tuition Classes?

Find best tutors for BTech Tuition Classes by posting a requirement.

  • Post a learning requirement
  • Get customized responses
  • Compare and select the best

Looking for BTech Tuition Classes?

Find best BTech Tuition Classes in your locality on UrbanPro

Post your learning requirement

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 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 6.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