For this Question: Your task is to implement a stack using a linked list and perform given queries

Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
 <b>push()</b>:- that takes the integer to be added as a parameter.
 <b>pop()</b>:-   that takes no parameter.
 <b>top()</b> :-   that takes no parameter.

Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2 
top
pop
top
pop
top

Output:
2
1
0
, I have written this Solution Code: 
 Node top = null;
   public void push(int x) 
    { 
       
        Node temp = new Node(x); 
     
     
        temp.next = top; 
   
        top = temp; 
    } 

  
  
    public void pop() 
    { 
 
        if (top == null) { 
           
        } 
        else {
        top = (top).next;} 
    } 
  
    public void top() 
    { 
        // check for stack underflow 
        if (top == null) { 
            System.out.println("0"); 
        } 
        else { 
            Node temp = top; 
      
  
                System.out.println(temp.val); 
  
             
        } 
    }
, In this Programming Language: Java, Now tell me if this Code is compilable or not?