if two overloaded methods are:
class Test
{
public static void main(String as[])
{
Test t=new Test();
t.m1(null);
}
public void m1(Object obj)
{
System.out.println("m1 with obj");
}
public void m1(Customer c)
{
System.out.println("m1 with Cust");
}
}
which method will be called and why?
Ans: Jvm
will choose the most appropriate methods.Here, we need to know which
class is more specialized, Object or Customer.The Customer class is the
specialization of Object class.So Customer type method will be called.
No comments:
Post a Comment