My app has a structure similar to this:
class Father{
a(){ ... }
b(){a();}
}
class Son extends Father{
a(){ ..... }} //override
b() is not overrided.
When I create an instance of Son and I call b(), Father’s a() is called, but I would like it executes the Son one (if the object is a Son). Is it possible?
Son’s
amethod should be called. If it’s not, then you’re either not operating on an instance ofSonor you haven’t correctly overridden the method. This could happen if the signatures aren’t exactly the same. I would double check in your implementation that the signatures are exactly the same. Also, try throwing an@Overrideabove theSonimplementation ofaand see if you get a compile error. If you do, then you aren’t overriding the method correctly.Like this
Also,
amust be either protected or public (package private, the default, will only work ifFatherandSonare in the same package). i.e.Sonmust be able to “see” thea()method.