• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling a method without link.  RSS feed

 
Harold Lauder
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello. Can someone explain to me why method getName() in 11 7 induce himself without any link`s before him. Like max.getName().
[edit]CR: corrected line number to 7.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harold Lauder wrote:
Hello. Can someone explain to me why method getName() in 11 induce himself without any link`s before him. Like max.getName().


From the context of an instance method, when you call an instance method like getName(), the Java compiler will assume that you mean this.getName()... meaning it assumes to use the same instance as the instance method call.

Henry
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an implied "this." reference in front of it which refers to the current instance of PriorThread whose run() method is being executed. The call to getName() is made to that same instance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!