Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

Question about inheritance: Lets say there is a Super class which has void f(), void g(), and void h(). And there is a Sub class that extends Super and has it's own void f(), void g(), void h(int n). If you did Super s1 = new Sub(), why wouldn't s1.h(1) work?

OpenStudy (anonymous):

i know that s1.h() will call the Super class's h() method but I don't understand why h with parameter is not calling subclass's h while others like s.f() and s.g() calls subclass's methods

OpenStudy (anonymous):

i meant s1.f() and s1.g()

OpenStudy (konradzuse):

Well if the sub has it's own method it should work.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!