Automatic Type Promotion in Overloading in Java (original) (raw)

Last Updated : 4 May, 2026

Automatic type promotion in Java occurs when a smaller data type is automatically converted to a larger data type during method overloading. It helps the compiler choose the most suitable method when an exact match is not available. This feature ensures flexibility and avoids compilation errors in overloaded method calls.

small_size_datatype

**Note:- This is important to remember is Automatic Type Promotion is only possible from small size datatype to higher size datatype but not from higher size to smaller size. i.e., integer to character is not possible.

**Example: In this example, we are testing the automatic type promotion from small size datatype to high size datatype.

Java `

class GFG {

// A method that accept double as parameter
public static void method(double d)
{
    System.out.println(
        "Automatic Type Promoted to Double-" + d);
}

public static void main(String[] args)
{
    // method call with int as parameter
    method(2);
}

}

`

Output

Automatic Type Promoted to Double-2.0

**Explanation: Here we passed an Integer as a parameter to a method and there is a method in the same class that accepts double as parameter but not Integer. In this case, the Java compiler performs automatic type promotion from int to double and calls the method.

**Example: Let's try to write a code to check whether the automatic type promotion happens from high size datatype to small size datatype.

Java `

class GFG {

// A method that accept integer as parameter
public static void method(int i)
{
    System.out.println(
        "Automatic Type Promoted possible from high to small?");
}

public static void main(String[] args)
{
    // method call with double as parameter
    method(2.02);
}

}

`

**Output:

Error message

**Explanation: From this example, it is proven that Automatic Type Promotion is only applicable from small size datatype to big size datatype. As the double size is large when compared to integer so large size to small size conversion fails.

**Example: In this example, we are going to look at the overloaded methods and how the automatic type of promotion is happening there.

Java `

class GFG {

// A method that accept integer as parameter
public static void method(int i)
{
    System.out.println(
        "Automatic Type Promoted to Integer-" + i);
}

// A method that accept double as parameter
public static void method(double d)
{
    System.out.println(
        "Automatic Type Promoted to Double-" + d);
}

// A method that accept object as parameter
public static void method(Object o)
{
    System.out.println("Object method called");
}

public static void main(String[] args)
{
    // method call with char as parameter
    method('a');
  
    // method call with int as parameter
    method(2);
  
    // method call with float as parameter
    method(2.0f);
  
    // method call with a string as parameter
    method("Geeks for Geeks");
}

}

`

Output

Automatic Type Promoted to Integer-97 Automatic Type Promoted to Integer-2 Automatic Type Promoted to Double-2.0 Object method called

**Explanation: In the above code,

**Example: In this example, consider the overloaded methods with more than one argument and observe how automatic type conversion is happening here:

Java `

class GFG {

// overloaded methods
// Method that accepts integer and double
public static void method(int i, double d)
{
    System.out.println("Integer-Double");
}
// Method that accepts double and integer
public static void method(double d, int i)
{
    System.out.println("Double-Integer");
}
public static void main(String[] args)
{
    // method call by passing integer and double
    method(2, 2.0);
    // method call by passing double and integer
    method(2.0, 2);
    // method call by passing both integers
    // method(2, 2);
    // Ambiguous error
}

}

`

Output

Integer-Double Double-Integer

**Explanation: In the above code,

Ambiguity Error

These are the few examples that can give clear insight on Automatic type conversion in overloaded methods.