Hi,
Does the meaning of method signature is different with respect to Overloading an Overriding.
As per the books , method signature includes method's name ,the number and type of arguments passed to it. The return type have no role in the signature.(Correct me if i am wrong)
For eg. Consider this Code
In Overloading
class T
{
public void goo()
{
System.out.println("true");
}
public int goo()
{
System.out.println("false");
return 1;
}
}
class OverLoad
{
public static void main(
String arg[])
{
T ob = new T();
ob.goo();
}
}
this wont compile the compiler says
goo() is already defined in T
----------------------------------------------------------------
But In Over-ridding
class T
{
public void goo()
{
System.out.println("true");
}
}
class OverLoad extends T
{
public int goo()
{
System.out.println("true");
return 1;
}
public static void main(String arg[])
{
T ob = new OverLoad();
ob.goo();
}
}
if i change the return type here , the compile complains
goo() in OverLoad cannot override goo() in T; attempting to use incompatible return type
found : int
required: void
public int goo()
it seems that
return type has some role in the method signature during overridding,otherwise it wont have given the error.
thanx in advance
