The problem is in the System.out.println instruction

Whenever we write any operator to print to the console in a Java program:

System.out.print or System.out.println

In both statements above, we call the reference variable of the PrintStream object without explicitly importing the java.io package, since we get access to these object methods without causing any compile-time error?

+5
source share
3 answers

The System object has links to java.io.PrintStreamobjects embedded in it. Therefore, you do not need to explicitly import this data - the runtime can get this information unambiguously, since it was implemented at compile time.

, PrintStream , . , ( , ).

( ), java.lang , System import.

+6

, . , :

PrintStream out = System.out;

, java.io.PrintStream, off System.out, "" , , System.out. , Scala, , .

+4

- , , . java.io.File file = new java.io.File("foo.txt") , File file = new File("foo.txt").

.

, , , .

( )

+3

All Articles