Please don't be angry if my question is stupid )
I have a piece of code:
public class LinkageTest {
public static class Parent {
public void test() {
System.out.println("parent::test");
}
}
public static class Child extends Parent {
public void test() {
System.out.println("child::test");
}
}
public static class Tester {
public void test(Parent obj) {
System.out.println("Testing parent...");
obj.test();
}
public void test(Child obj) {
System.out.println("Testing child...");
obj.test();
}
}
public static void main(String[] args) {
Parent obj = new Child();
Tester t = new Tester();
t.test(obj);
}
}
When I'm running it, the next string is printed:
Testing parent... child::test
I can't understand why test method with Parent is called if we have instance of Child? Can some one help me with it?