0
openjdk version "1.8.0_121"

Just looking at some sample code where ServiceResultHandler extends the Handler class.

public class ServiceResultHandler extends Handler {
}

In other classes where this is used I have seen it been declared like this:

private Handler mServiceResultHandler;

and being instantiated like this:

mServiceResultHandler = new ServiceResultHandler();

My question is shouldn't mServiceResultHandler be a ServiceResultHandler instead of a Handler i.e?

private ServiceResultHandler mServiceResultHandler

Just seems odd to me to have the type as Handler when ServiceResultHandler inherits all the attributes of the Handler class anyway.

ant2009
  • 27,094
  • 154
  • 411
  • 609
  • I am sorry I have read through this twice now and still don't fully understand your question, is it what `extends x` means or just why it is inherited? – Fireapprentice Feb 09 '17 at 10:25
  • The question is - If `Handler` were an interface, it makes sense to declare `Handler msrh = new MSRH();`, but currently, it is a parent class. **Does it make sense to declare a child class object as a parent class type?** – Pavan Kumar Feb 09 '17 at 10:33
  • I think this kind of question has been asked before, here is a link to a post which can hopefully help you: http://stackoverflow.com/questions/56867/interface-vs-base-class – Fireapprentice Feb 09 '17 at 10:37
  • @PavanKumar Handler is just a public class. – ant2009 Feb 09 '17 at 10:43
  • @Fapprentice I can understand if Handler was an interface. But its just a normal class. – ant2009 Feb 09 '17 at 10:45

0 Answers0