I have never really understood why code such as that given below is valid and would really appreciate it if someone helped me out.
public class A{
int x;
int y;
void hello() {
System.out.println("Hello World");
}
public static void main(String[] args) {
A my_instance = new A();
my_instance.hello();
}
}
OUTPUT:
Hello World
Question: Why are we allowed to create an instance of A inside one of its own static methods?
I understand that static methods belong to the class and not any particular instance, but does this mean that under the hood the compiler first analyzes everything that's not static and makes that code available to static methods?