Understanding Java class variable System.out?
I know this answer is correct. I'm concerned about understanding.
That means for me:
There's a class called Printstream, and it has a class variable called System. This class variable, System, itself has a class variable called out , which I call via System.out. Is that correct?
Let's continue to understand System.out.println(…):
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/System.html
I have now called the class System under Java docs
Field Summary: These are the attributes of the System class
Here I also find the attribute or field out
That means out is static => belongs to a class, here to System
final => Attribute out is not changeable
Printstream => This means that the attribute out itself has the data type Printstream
In the Printstream class there is the method println(…)
Right so far?
No.
There is a class “system” and it has a variable called “out” that is of the type “PrintStream”.
(In the past, the “PrintStream” class is written in the Camel case, not “Printstream”.)
Yeah.
However, it is possible to change the stream iirc, but it may also be changed internally, so that the variable is not changed (but possibly forwarded to another stream).
EDIT: Okay, can also be that the Internal simply bend the reference under the hood. See: https://stackoverflow.com/questions/26903799/how-is-the-final-variable-system-out-changing-its-reference )
“However, you can change the stream”
iirc?
“if I recall correctly”
But not confused with IRC. ๐
cool;-)
That’s wrong.
PrintStream has no class variable โSystemโ.
The rest is true.