abstract class Cell<Q> {
public abstract Q getValue(); // abstract method
}
class Cell1 extends Cell<Integer> {
public Integer getValue() {// abstract method implementation
return 0;
}
}
class Cell2 extends Cell<String> {
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.
Or you can say different number of arguments.
what you are doing is overriding.