title: How to access class(implements Runnable) field
body: <p>i want to control thread by input value.</p>
  
  <p>if input value is 1 than do something.</p>
  
  <p>else nothing.</p>
  
  <pre><code>class Main {
    class test implements Runnable{
      public boolean flag = true;
      public int val = 0;
  
      @Override 
      public void run(){
        while(true){
          if(flag == true){
            pt();
          }
        }
      }
  
      public void pt(){
        System.out.println(val++);
        flag = false;
      }
    }
  
    public static void main(String[] args) {
      Main m = new Main();
      test r = m.new test();
      Thread t = new Thread(r);
      t.start();
  
      Scanner reader = new Scanner(System.in);
      while(true){
        int n = reader.nextInt();
        if(n==1){
          r.flag = true;
          // t.flag = true;
        }
        else{
          r.flag = false;
          // t.flag = false;
        }
     }
    }
  }
  </code></pre>
  
  <p>This is my code.</p>
  
  <p>Obviously, 
  I knowing that r.flag does not change the value of Thread t.
  So, even if typing 1, Nothing happens.
  but t.flag is impossible. object t have not variable flag.</p>
  
  <p>How to access t.r.flag .... can you understand?</p>
  
  <p>I think something is making a lot of fools right now.</p>
  
  <p>Am I going in a wrong direction?</p>