How does System.out.print() work?

后端 未结 9 2230
鱼传尺愫
鱼传尺愫 2020-11-27 03:40

I have worked with Java for a quite a long time, and I was wondering how the function System.out.print() works.

Here is my doubt:

Being a functi

9条回答
  •  野性不改
    2020-11-27 04:22

    The scenarios that you have mentioned are not of overloading, you are just concatenating different variables with a String.

    System.out.print("Hello World");
    
    System.out.print("My name is" + foo);
    
    System.out.print("Sum of " + a + "and " + b + "is " + c); 
    
    System.out.print("Total USD is " + usd);
    

    in all of these cases, you are only calling print(String s) because when something is concatenated with a string it gets converted to a String by calling the toString() of that object, and primitives are directly concatenated. However if you want to know of different signatures then yes print() is overloaded for various arguments.

提交回复
热议问题