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 function, it has a declaration somewhere in the io package. But how did Java developers do that, since this function can take in any number of arguments and any argument types no matter how they are arranged? e.g:
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);
No matter what is the datatype of variables a, b, c, usd, foo
or how they are passed, System.out.print()
never throws an error.
For me, I have never worked on any project where the requirement was like this. Provided, if I get a requirement like this, I really don't know how to solve it.
Can anyone explain to me how it's done?
System.out.print
(PrintWriter
) certainly does not support your lines 2 to 4, it has no such a method. – BarnabaSystem.out.print()
, as commas are used to separate different parameters andSystem.out.print()
accepts 1 parameter.. Concatenation between strings is done by using the+
operator. – Farhi,
a typo? instead of+
? – Screwed