I posted this before using an example of a zookeeper and different kinds of animals, but I think my explanation of my question was not clear enough, so I will try again.
Suppose I have this:
The methods finalAnswerB and finalAnswerC are identical except that they call a different method. And they are so long that I really do not want to have them written out twice. So here is where I can take advantage of polymorphism:
In the second example, an object is passed to the finalAnswer method. However, it seems strange to me because the answer method is a static method, and usually you do not have to make an object in order to use a static method. In this case, I really should not have to make an object, I think. If it is possible, I would rather pass the class name (B or C) to the finalAnswer method, or pass the name of a method to the finalAnswer method. Is it possible to do that in java?
You should note that the version in class C will not get called since statics methods do not take part in polymorphism. Hence you do not override from B but redefine. And the method that makes the call to answer(int x) takes B as an argument.
JDBCSupport - An easy to use, light-weight JDBC framework -
The reflection API allows you to get / set variables, call methods, and instatiate objects -- all without knowing the name of the classes , the name of the methods, or the name of the variables, at compile time.