In the getName method, don't we need to specify it as
public String getName() {
return this.name; // rather than just 'return name'?
}
getName method clarification
Resolved
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Paul Harman
28 April 2020, 03:42
the use of "this" is good practice but not essential in this case
0
Janusz
27 October 2018, 21:37
public String getName() {
String name = "Azor";
return name;
}
0
Abhilash Ravichandran
3 September 2018, 15:56solution
Thanks, learnt that the compiler will decide on whether to work on instance variable of object 1 or 2 by implicitly adding "this" keyword.
+2
Vartaman Ingole
28 November 2018, 09:50
this differentiates the instance variable from local variable
+1
Roman
3 September 2018, 11:10solution
Try to read about "this" in java.
+2