It:
{
Test test = new Test();
test.anotherMethod();
}
- . Test. Test, , , , Test, ... .
, ?
, . , , , ( , ) super ( , ). , , , , .
?
, " ", , . , , static:
public class Test {
public static void main(String[] args) {
Test test = new Test();
}
{
System.out.println("Instance execution");
}
private void anotherMethod() {
System.out.println("Method execution");
}
static
{
System.out.println("Class initialization");
Test test = new Test();
test.anotherMethod();
}
}
:
Class initialization
Instance execution
Method execution
Instance execution
( " " , new Test main, static.)
anotherMethod main:
public class Test {
public static void main(String[] args) {
Test test = new Test();
test.anotherMethod();
}
{
System.out.println("Instance execution");
}
private void anotherMethod() {
System.out.println("Method execution");
}
}
Instance execution
Method execution