Can we overload same signature but different return types? is it possible.
yes it is possible.
here we have 2 classes a(class) and b(class)
if you create object to the a (class) ----method add(int a,int b) is invoked and returns integer value
and
if you create object to the b(class)-----method add(int a,int b) is invoked and returns float value
overloading is possible in derived classes are:
1. number of parameters in the signature of the method.
2. order of the parameters in the signature of the method.
Polymorphism : the main objective of polymorphism is giving multiple behaviors to single method.
Inheritence:code reuseablity.
overloading main objective is giving new functionality to derived class method (of parent class).
advantage is performance.
public class a
{
public int add(int a, int b){return a+b;}
}
public class b:a
{
public float add(int a, int b) { return a * b; }
}
i was given new functionality to b class.
now this is real need of the overriding a method in derived class.
conclusion : if parent class ( a class) functionality is not suitable to our requirement. write new functionality in derived class.
if it is helpful please marked as answer
kasi babu
Software Engineer.
Regards,
Kasi babu
Naga116, if this helps please login to Mark As Answer. | Alert Moderator