My Class Architecture goes like this.
I have an interface “myInterface”. I create a class “mySuperMostClass” which implements “myInterface”. Now i create a class “myBaseClass” which extends “mySuperMostClass”. Then i create “mySubClass” which extends “myBaseClass”. I have overridden the methods “methodA”, “methodB” from “myBaseClass” in “mySubClass”.
“methodB” is called from “methodA”
Now i create an object for mySubClass and refer it with instance of “myInterface”. When i call methodA with the instance of myInterface, the implementation from “myBaseClass” is called. But i want it to call “mySubClass”. Kindly help me to do this.
I am using Java 1.5
First of all, I’m sure that your actual class names don’t start with lowercase. If they do, I would suggest that you read about Java Naming Convention
When overriding methods from your parent class make sure that the method signature remains consistent. For example, if you have a method called
public void method(String input), you’ve to make sure that the same signature is maintained in the child class.So, from reading your question, I assume the correct implementation would be something like this:
Note: I’m not so sure of the actual signature of your methods, hence I’ve kept them as parameterless. In your case, make sure that the signature remains the same.
And the way you would call would be something like this: