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

Fractional Knapsack
Algorithm - Fractional Knapsack import java.util.Scanner; public class Knapsack01 { public static void main(String args) { Scanner scan = new Scanner(System.in); int...

Stiffness Modification In Analysis
Stiffness modification: Significance In IS 456,as per Cl.22.3 gross sectional properties are allowed to be used (if consistently used for all members) for force calculations. For deflections, 22.3.2 allows...

What is buttress dam?
Buttress Dam consists of a watertight upstream side, usually reinforced concrete, supported by triangular-shaped walls, called buttresses on the downstream side. This kind of dam uses less concrete compared...

Java
Java is a high level language which is far better than procedural languages like C, Fortran and Pascal. Java completely stands with the principles of OOPS (Object Oriented Programming Structure). The...
A

Abhisheak Saxena

0 0
0

Wheeled Robots
For safety, speed and fuel efficiency, when designing recreation and transportation vehicles, engineers take into account all forces acting on the object. Engineers consider drag forces when they design...
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