Junior — Middle
What type of method binding is used during method overloading?
sobes.tech AI
Answer from AI
Method overloading in Java uses static binding. This means that the specific version of the method is chosen at compile time based on the types of the parameters with which the method is called.
For example:
class Example {
void print(int a) {
System.out.println("int: " + a);
}
void print(String s) {
System.out.println("String: " + s);
}
}
// When calling print(5), the compiler binds the call to the print(int a) method
// When calling print("hello"), it binds to the print(String s) method