Please see the code below. I'm confused about the overridden method calls which occur during constructor chaining from derived to base....
class sup
{
int val;
public sup()
{
System.out.println("Executing super");
this.func(); // (2)
System.out.println("Exiting super");
}
protected void func()
{
val = 10;
System.out.println(val);
}
}
public class sub extends sup
{
public static void main(
String args[])
{
sub i = new sub(); // (1)
}
protected void func() // (3)
{
}
}
Output of above code is:
"Entering super"
"Exiting super"
My question is that when base class constructor is called through derived class' constructor, why the version of func in derived class is called and not in base, while base class constructor explicitly calls its own version of function through this. Hope you guys understand my question.