I understand that in Java all method calls go on a stack. Take the following class for instance:
Class Demo
{
// Some instance variables
public Demo()
{
initialize();
}
public void initialize()
{
// Start initialization
....
// Call another method to perform some complex calculation
int resultVal = helperMethod();
// Perform the remaining initialization work
}
public int helperMethod()
{
// Perform some complex calculation
....
return result;
}
}
First initialize()
(with its state) is pushed onto the stack and then when it calls helperMethod()
,state for helperMethod()
is pushed onto the stack too.
But what i want to understand is , is state for Demo()
first pushed onto the stack (before even initialize()
is pushed) , despite it being a constructor and not a method ?
Are there notable differences between saving constructor state and method state ?