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

Software Testing
Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifying that a software program...

Inheritance In Java
Inheritance: The process of getting properties and behaviors from one class to another class is called inheritance. Properties: Variables Behaviors: Methods The main purpose of the inheritance...
D

Deleted U.

1 0
0

Role of numerical methods in Electronics & Communication and Electrical Branches and how to deal with it.
1) Role of Numericals: These problems are based on realizing circuits, being a R&D engineer, I would like to suggest all students to lay emphasis on Numerical Problems as they are very important both...

DUCTILE DETAILING AND ITS SIGNIFICANCE + HOW TO ACHIEVE DUCTILITY
Ductility of Buildings is a key virtue. Ductility is the ability to prolong yielding or in simple words, prolonging deformation and failure.Why should we prolong yielding of steel?As we know, we design...

Structure And Function
A computer is a complex system; contemporary computers contain millions of elementary electronic components.How,then,can one clearly describe them? The key is to recognize the hierarchical nature of most...
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