# # introduction

I was asked in the spring recruitment interview how do you understand system.out.println ()?

After learning so much about object-oriented programming, how do you do it in one line of code?

If you can read System.out.println() for yourself, you really know what Java object-oriented programming means

Object oriented programming is creating objects and letting object helpers do everything themselves (that is, objects call methods)

System.out.println("hello world");

Copy the code
hello world

Process finished with exit code 0

Copy the code

First analyze the System source code

System is a Java custom class


Out source code analysis

Out is a static data member of the System, and this member is a reference to the java.io.PrintStream class

Out = system.out = system.out = system.out = system.out = system.out


Println analysis

Println () is a java.io.PrintStream method that outputs information to the console.

② There are many overloaded methods in it, so that anything can be output

To summarize, classes call objects, and objects call methods


Expand knowledge:

1.System.out.print(); With the System. The out. Println (); The difference between


  • 2. Character array output interview cases
public class Demo {

    public static void main(String[] args) {
        char[] ch=new char[]{'x'.'y'};
        System.out.println(ch);

        char[] ch1=new char[]{'x'.'y'};
        System.out.println("ch1="+ch1); }}Copy the code
xy
ch1=[C@74a14482

Copy the code

This is an overloading of the println() method. Java printing system.out.println automatically calls the toString method of the input parameter and returns the value of the toString method.

Println has two basic types, one is String and the other is Object.

System.out.println(ch) println() automatically calls println(char[]), which is the Object type so it prints xy

System.out.println(” ch= “+ ch) “+” is a String concatenator, which automatically calls println(String).

As we step into the details, we find that by calling toString(), we can override it.