System and exit in java

I am a new java user. I recently found out that out (which we use with System.out.println ) is the standard java output object.

My question is: I never created this object myself or did not find any code that creates this object. So how is it available for use?

And what's more, I think System is the name of the class. If so, then out is a static member of the System class, since we access out without creating a new object of the System class?

+6
source share
3 answers

Yes, the system is a class, and out is the static member variable of this class.

 public final class System { public static final PrintStream out = ...; public static final PrintStream err = ...; public static final InputStream in = ...; ... } 

See the Java documentation for the System class.

+8
source

yep, it lives on a System object:

 public final static PrintStream out = null; 
+3
source

A good way to learn the language (and get the right answers) is to look at the source of the API. in System.java

 ... public final static PrintStream out = null; ... 

you do not need to create an object to access static members

+3
source

Source: https://habr.com/ru/post/984031/


All Articles