Calling variables from other class <pre><code>import java.util.Scanner; public class ThreadClass{ public static void main(String[] args) { System.out.println("Enter the characters, Press Enter to begin"); System.out.println("The quick brown fox jumps over the lazy dog"); Scanner sc=new Scanner(System.in); String scr= sc.nextLine(); MyThread tr=new MyThread(); try { tr.sleep(11000); System.out.println("Time Over"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public class MyThread extends Thread{ public void run() { System.out.println("Time over"); ThreadClass tc=new ThreadClass(); String str=tc.scr; if(str.equals("The quick brown fox jumps over the lazy dog")) { System.out.println("Successfully completed"); } else { System.out.println("The typed Words do not match"); } } } </code></pre> <p>I am trying to make an application that prompts the user to type a string within 11 seconds. To accomplish this I have two classes namely ThreadClass and MyThread. In Thread class I have defined methods to take input from the user and to set the timer to 10 seconds. In MyThread class I have defined methods for post thread completion i.e. what the program will do after the time is over. I want to add a feature in MyThread class so that it compares the user input with the string provided. The problem is that when I try to access the String variable scr, defined in ThreadClass from MyThread class by creating an it gives me an error. Even if I try to extend ThreadClass from MyThread class it gives me an error. Also declaring scr as static gives me the same result. Is there any possible way to use scr variable in MyThread?</p>