by Dinesh Thakur Category: Classes

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.

 Overloaded methods may or may not have different return types. When java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call.


However, this match need not always be exact. In some cases java’s automatic type conversions can play a role in overload resolution. Java will employ its automatic type conversion only if no exact match is found.
The important points to note:


    A difference in return type only is not sufficient to constitute an overload and is illegal.

    You should restrict your use of overloaded method names to situations where the methods really are performing the same basic function with different data.

    The language treats methods with overloaded names as totally different methods and as such they can have different return types. However, since overloaded methods perform the same job with different data sets, they should produce same return type normally. There is one particular condition, however, under which it is sensible to define different return types. This is the situation where the return type is derived from the argument type and is exactly parallel with the arithmetic operators.

    Overloaded methods may call one another simply by providing a normal method call with an appropriately formed argument list.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles