'How does var-arg affect overloading?
class Student
{
void cal(int ...x)
{
System.out.println("Parent");
}
}
class HelloWorld extends Student
{
void cal(int x)
{
System.out.println("Child");
}
public static void main(String... args)
{
Student ref = new HelloWorld();
ref.cal(10);
}
}
OUTPUT: Parent
While compiling, the compiler checks whether cal(int) is present in Student class or not. Once confirmed, when running the JVM tries to match the cal(int) based on the runtime object i.e. HelloWorld in this case. So it should match cal(int) with cal(int x) and the output should be "Child".
So then why is the output "Parent"
Above logic derived from: https://stackoverflow.com/a/70903492/13146358
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
