This is rather basic question. But I can't understand well the concept of inheritance.
Suppose I have two classes, A and B with both have a test()
method that returned 1
and 2
respectively, and B inherited A class. In main method I declare the instance as such;
A a1 = new B();
and call the method a1.test()
, it will return 2
. This is the concept of polymorphism. But when I have a method test2()
in just subclass, I can't call the method using the same instance declaration as above. Why is that happen?