Q:

How can I declare an instance variable(of type inner class) in the outer class?

I want to declare an instance in the outer class, before I have defined the inner class, but in code blew its cause issue:
class LinkedList 
{ 
    Node head; //line3

    class Node //line5
    { 
        int data; 
        Node next; 
        Node(int d) 
        { 
            data = d; 
            next = null; 
        } 
    }

    public void push(int new_data) 
        { 

            Node new_node = new Node(new_data); //line 20

            new_node.next = head; 

            head = new_node; 
        } 

In line 3, I am confused why you are able to create an instance variable of type Node when it is before you define what the Node class is in line 5. 
Also, hypothetically if I wanted to create an instance variable in the Node class of type Linkedlist, would it let me do that?
In the push method in line 20, when it creates a new Node instance, does it also create a new LinkedList instance, because Node is the inner class of LinkedList?

A:

You can do that because the Java Compiler is smart, and can look ahead.
It is also why you can have two classes A and B in separate source files, where A refers to B, and B refers to A, i.e. a circular dependency, and it will compile ok, as long as you compile both at the same time.
You don't even have to name both classes when compiling. When the compiler is compiling A and sees a reference to B, it will automatically look for the source code for B and compile that too, in the same compilation job. That way, the compiler can look ahead to know which types exist, before parsing the member declarations.

