Why is this printing NULL?
<p>I was wondering if anyone could tell me why I was getting the output 'NULL' when running this and setting the names. I have done a return method to return names from setName but it still appears as null as if they haven't been set.</p>

<p>What is supposed to happen is - run the main menu - set the names - then run the Play method in gameBoard.java and see the names in there - but I can only see null.</p>

<p>Main Class:</p>

<pre><code>import java.lang.reflect.Array;
import java.util.Random;
import java.util.Scanner;

public class main {


    public static void main(String[] args) {

        setName SN = new setName();
        gameBoard GB = new gameBoard();
        Scanner user_input = new Scanner(System.in);
        int mainMenuChoice = 0;
        String p1Name = null;
        String p2Name = null;

        while(mainMenuChoice &gt;= 0 &amp;&amp; mainMenuChoice &lt; 3){

            if(mainMenuChoice == 0){
                if(p1Name != null){
                    System.out.println("Welcome " + p1Name + " and " + p2Name + " to AQADo! ");
                }
                System.out.println("MAIN MENU");
                System.out.println("1. Enter Player Names");
                System.out.println("2. Play Game");
                System.out.println("3. Quit");
                System.out.println("Select your number");
                mainMenuChoice = Integer.parseInt(user_input.next());
            }
            if(mainMenuChoice == 1){
                p1Name = SN.setName1();
                p2Name = SN.setName2();
                mainMenuChoice = 0;
            }
            if(mainMenuChoice == 2){
            int menu = 1;
            int[] p1score = {};
            Random rn = new Random();
                GB.board();
                GB.play();
                String test = user_input.next();
                for(int i = 0; i &lt; 50; i++){
                    p1score[0] = rn.nextInt(6);


                mainMenuChoice = 0;

            }

        }


    }



    }
}
</code></pre>

<p>setName class:</p>

<pre><code>    import java.util.Scanner;

public class setName {
    public String GlobalP1;
    public String GlobalP2;


    public String setName1(){
        Scanner user_input = new Scanner(System.in);
        String p11Name;
        System.out.println("Enter the first players name:");
        p11Name= user_input.next();
        GlobalP1 = p11Name;

        return p11Name;
    }
    public String setName2(){
        Scanner user_input = new Scanner(System.in);
        String p22Name;
        System.out.println("Enter the second players name:");
        p22Name= user_input.next();
        GlobalP1 = p22Name;


        return p22Name;
    }
    public String GBName(){
        return GlobalP1;
    }
    public String GBName2(){
        return GlobalP2;
    }
}
</code></pre>

<p>gameBoard Class:</p>

<pre><code>public class gameBoard {

    setName SN = new setName();

    char[] array1 = new char[11];{
    array1[0] = 'x';
    array1[1] = 'x';
    array1[2] = 'x';
    array1[3] = 'x';
    array1[4] = 'x';
    array1[5] = 'x';
    array1[6] = 'x';
    array1[7] = 'x';
    array1[8] = 'x';
    array1[9] = 'x';
    array1[10] = 'x';
    }
    char[] array2 = new char[11];{
    array2[0] = 'x';
    array2[1] = 'x';
    array2[2] = 'x';
    array2[3] = 'x';
    array2[4] = 'x';
    array2[5] = 'x';
    array2[6] = 'x';
    array2[7] = 'x';
    array2[8] = 'x';
    array2[9] = 'x';
    array2[10] = 'x';
}

    public void board(){


        System.out.println("           1  2  3  4  (5)  6  7  8  9  10  11");
        System.out.println("Player 1:  " + array1[0]+ "  " + array1[1] + "  " + array1[2]+ "  " + array1[3] + "   " + array1[4]+ "   " + array1[5] + "  " + array1[6]+ "  " + array1[7] + "  " + array1[8]+ "  " + array1[9] + "   " + array1[10]);
        System.out.println("Player 2:  " + array2[0]+ "  " + array2[1] + "  " + array2[2]+ "  " + array2[3] + "   " + array2[4]+ "   " + array2[5] + "  " + array2[6]+ "  " + array2[7] + "  " + array2[8]+ "  " + array2[9] + "   " + array2[10]);


    }
    public void play(){
        String p1Name = SN.GBName();
        String p2Name = SN.GBName2();
        String pArray[] = {p1Name,p2Name};


        System.out.println(p1Name + " test");

    }
}
</code></pre>

<p>Console output:</p>

<pre><code>    MAIN MENU
1. Enter Player Names
2. Play Game
3. Quit
Select your number
1
Enter the first players name:
Jordan
Enter the second players name:
David
Welcome Jordan and David to AQADo! 
MAIN MENU
1. Enter Player Names
2. Play Game
3. Quit
Select your number
2
           1  2  3  4  (5)  6  7  8  9  10  11
Player 1:  x  x  x  x   x   x  x  x  x  x   x
Player 2:  x  x  x  x   x   x  x  x  x  x   x
null test
</code></pre>