• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions on a segment of java code

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the following segment of java code, the method of “run” occurs four times. I am quite confusing about the relationships of these four occurrences of “run”. Can you explain this to me? The original code is pretty long, I just keep the part that is related to my question.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's first look at the two methods in the class, lines 9 and 13. These are two methods both called run but with different arguments and a different return type. Note that in line 10, the first run method calls the other one (from line 13). In line 15, this method calls a run method in a completely different class (ClusterDriver) that you didn't show.

In the main method, on line 5, the run method of line 13 is called on a new Job object.
 
cake naiyou
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Can I understnd the invoking sequence of this segment of code as follows:

At first, he run method at line 5 is called. Due to its particular parameter setting, 3 parameters, the compiler automatically uses the run method defined in line 13. ( if we only have one parameter in line 5, then compiler will use the run method defined in line 9 instead.

For the run method defined in line 9, it will call run method at line 10, which essentially is the run method defined at line 13.


Is my understanding correct?

Jesper de Jong wrote:Let's first look at the two methods in the class, lines 9 and 13. These are two methods both called run but with different arguments and a different return type. Note that in line 10, the first run method calls the other one (from line 13). In line 15, this method calls a run method in a completely different class (ClusterDriver) that you didn't show.

In the main method, on line 5, the run method of line 13 is called on a new Job object.

 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.

If there are two methods with the same name in the same class, Java will look at the number and types of the arguments to decide which one to call.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic