Accessing field of one field from another?
<p>Like say I had two classes, <code>Class1</code> and <code>Class2</code>, and I want to make an <code>if</code> statement in <code>Class2</code> using a field (example:<code>int option</code>) from <code>Class1</code>.</p>

<p>I tried creating an object:</p>

<p><code>Class1 object = new Class1();</code></p>

<p>in <code>Class2</code>, then writing the <code>if</code> statement:</p>

<pre><code>if(object.option == 2)
</code></pre>

<p>But it didn't work.</p>

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

public class Class1 {
    public static void main(String[] args) {
        Class2 obj = new Class2();
        int option;
        Scanner input = new Scanner(System.in);
        System.out.print("Enter an option of 1, 2 or 3");
        option = input.nextInt();
        obj.input();
    }
}

public class Class2 {

    public void input(){
        Class1 object = new Class1();
        if(object.option == 1){
            System.out.print("You've selected the option 1");
        }
        else if(object.option == 2){

            System.out.print("You've selected the option 2");
        }
        else if (object.option == 3){
            System.out.println("You've selected the option 3");
        }
    }
}
</code></pre>

<p>I get a compilation error: <em>option cannot be resolved to a field</em></p>
