+ 1
What is this() in java how does it work and how to use it inside a constructor in a print statement
if you have seen the new boston youtube channel 42 video tutotorial you know what i am talking about . in that video he uses printf("%s",this) which apparently points towards toString and constructor how does this work
4 Antworten
+ 6
Allows you to put string values inside a string without having to use +
String name = "Atharva";
System.out.printf("hi %s",name);
+ 6
Atharva its to convert the whole input stream to string which is an alternative way to string concatenation
+ 2
@D_Stark my doubt is if i use this instead of the place where you used name inside a constructor then how does it or why would it call the toString function
+ 1
this is a keyword that you can use to refer to the object, as simple as that. When you do printf("%s", this); the printf function will run the toString() since this = the object