By runnung the following code I got the result:
method from class A
method from class B.
public class Test {
static class A {
public A() {
someMethod();
}
public void someMethod() {
System.out.println("method from class A");
}
}
static class B extends A {
public void someMethod() {
System.out.println("method from class B");
}
}
public static void main(String... args) {
new A();
new B();
}
}
The first line of the result is clear but the second one isn't. Why didn't the constructor of the class A call the method defined in class A instead the overriden method of class B? Can it be that after compilation the code from constructor A is somehow copied to class B so that we actually call our method from class B?