I have the following,
public interface SuperbInterface
public class A implements SuperbInterface
public class B extends A
public class C extends B
I want to instantiate C
but I seems to be getting B
, what did I do wrong?
Class classz = Class.forName("C");
SuperbInterface superb = (SuperbInterface)classz.newInstance();
//Here when I debug it seems to be going to B.doWork() methods instead of C.doWork().
superb.doWork();
The only thing I can think of is that you haven't overridden doWork() in C.
Maybe you have tried ot override but with some spelling mistake in method name or wrong parameters?
Assuming you are using a newer version of Java add @Override to the doWork method. If you have incorrectly overriden the method the compiler will then let you know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With