i have a abstract class abs1
i have a method add() in abs1;
class a extends abs1
class b extends abs1
the add method was overriden in both classes a and b(both have add() method);
i am creating a reference for abs1 like abs1 xx=new abs1();
if i call xx.add(), which add() method will get called?
A method may have its return type as an abstract class or even an interface. It does not mean that it returns an instance of the abstract class or interface (none of which is possible).
In this case, the instance returned by the method is of one of the concrete child classes. For example, if your method is returning 'abs1', the actual instance returned by the method would be of class 'a' or 'b' (considering these are non-abstract classes).