0

Explain me this code's working please

https://code.sololearn.com/cd2m6X2qZPnF/?ref=app Also what if we replace printf with print why does it give error

4th Aug 2019, 3:47 AM
Ayush Pandey
Ayush Pandey - avatar
4 odpowiedzi
+ 1
more detailed, java.io.PrintStream.printf() and java.io.PrintStream.append() return PrintStream object so you can test if it is null. Printstream send chars from printf() and append() methods to output, ( to screen ). It is possible use printf() with only one parameter because other parameters are in Object... args, which can be empty. print return void so you cant test if it is null, because void is not object, it is keyword which means "no value is return". class java.io.PrintStream PrintStream printf​(String format, Object... args) PrintStream append​(CharSequence csq) void print​(String s)
4th Aug 2019, 9:13 AM
zemiak
+ 1
check how it returns object PrintStream import java.io.PrintStream; ... var s = new PrintStream(System.out); Object ps = s.printf("some text\n"); // some text System.out.println(ps == s); // true
4th Aug 2019, 9:29 AM
zemiak
0
zemiak bro you r too techinical I have not very advance in java but yeah I am getting somethig .It would be a great of u if u explain properlu
4th Aug 2019, 9:35 AM
Ayush Pandey
Ayush Pandey - avatar