abstract class Cell {
public abstract Q getValue(); // abstract method
}
class Cell1 extends Cell {
public Integer getValue() {// abstract method implementation
return 0;
}
}
class Cell2 extends Cell {
public String getValue() { // abstract method implementation
return "razeel";
}
}
class test
{
public static void main(String[] a)
{
Cell obj=new Cell1();
int ab=(Integer) obj.getValue();
Cell objs=new Cell2();
String str=objs.getValue().toString();
System.out.println("ab=================== "+ab);
System.out.println("String=================== "+str);
}
}
Can we call this an example of method overloading in java. If not why?
Is it possible to have methods with same signature but different return types in java?
解决方案
This is clearly not method overloading . Overloading means your method having different parameters return type has nothing to do with overloading.
public void method(int a,int b);
public void method(String s,int b);
Or you can say different number of arguments.
public void method(int a,int b,int c);
public void method(int a,int b);
what you are doing is overriding.