Will somebody please explain this piece of code for me. It's in task 1524 ,Order of Loading Variables.
{
System.out.println("Non-static block");
printAllFields(this);
}
What is it?
It's not under the static block and there's no method name.Is it a constructor and if so , should'nt it have the class name in front of it?
What is this codeblock?
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
GCPix Backend Developer
23 April 2020, 12:01
You might have got an answer to this if you also asked your question under the task but...
When you instantiate a new object, I am assuming you know that it will use the constructor to set values, if you don't have a constructor it uses the default (basic just public ClassName(){}) but before it does that it runs a few other things. It has been a while but I think the order is static block, non static block, constructor. Search for something like order of execution in java classes.
0