-2

private static Scanner sc;

&

sc.close();

What is the difference between these two things?

  • 3
    What makes you think those two things are similar? – Unmitigated Jan 04 '21 at 04:23
  • 1
    Your question is unclear. "private static Scanner sc;" declares a "Scanner" variable ... but leaves "sc" uninitialized. "sc.close();" closes a scanner object. I havwe no idea what the heck you mean by "&". IMPORTANT POINT: closing a scanner linked to System.in will close System.in itself: https://stackoverflow.com/questions/14142853/close-a-scanner-linked-to-system-in – paulsm4 Jan 04 '21 at 04:27

1 Answers1

1

These two concepts are unrelated. According to the Java documentation:

The private modifier specifies that the member can only be accessed in its own class.

See this thread to learn about Scanner.close().

Adrian Russo
  • 546
  • 4
  • 16