Is there any way I can use a Scanner object in a different class?
问题 So I have a simple Scanner object: Scanner scan = new Scanner (System.in); I am trying to use this Scanner object inside a method that I have declared in a different class. Is there anyway this can be done? I have also tried using: public static final Scanner scan = new Scanner(System.in); but this didn't really help 回答1: public static final Scanner scan = new Scanner(System.in); As you have declared Scanner instance as public and static . So you access it using the Class reference. Code in