import java.util.Scanner;
class Program
{
public static void main(String[] args)
{
Customer customer = new Customer();
Customer.method();
}
}
class Customer
{
**Scanner scan = new Scanner(System.in);**
public static void method()
{
System.out.print("Name : "); // error **non-static variable scan cannot be referenced from a static context**
String name = scan.nextLine();
}
}
Question :- while creating an Scanner class object outside the method() there is an compilation error :- non-static variable scan cannot be referenced from a static context but when i define it inside the method() it is working without error Why ?
Question :- How to create Scanner class Object that every class can use that single object which is defined at one place in a program. Is this possible ?