![]() |
Java Code Question (Method Calling)
Hi, I'm trying to learn java, and this is the first text-based programming language that I've gotten serious about. I am fairly proficient with labVIEW, so a lot of the syntax is new and kind of strange for me, but I digress. I have a particular question involving the following code. Also, if anyone could point me in the direction of any good learning resources for FRC java programming, that would be great. Thanks in advance!
Code:
package practicePackage;Why/how is it that the display method in the SolarSystem class calls the display method in the Planets class? Why is it that it doesn't call in itself recursively? If it helps, this is the output of the program. Mercury has 0 moons. Venus has 0 moons. Earth has 1 moons. Mars has 2 moons. Jupiter has 16 moons. Saturn has 18 moons. Uranus has 15 moons. Neptune has 8 moons. Pluto has 1 moons. |
Re: Java Code Question (Method Calling)
If I understand your question correctly - planets[i] references a Planet object, so it's going to call the display() method in that class.
|
Re: Java Code Question (Method Calling)
|
Re: Java Code Question (Method Calling)
@dcarr, Thanks a bunch. That seems to make a lot of sense now.
@markmcgary, thanks for the resources. |
Re: Java Code Question (Method Calling)
To expand further, to call SolarSystem's display method inside the SolarSystem class, you'd use just "display()" or "this.display()".
"this" is a reserved word that is a reference to the current object that the code is running in/from, and is usually implied, but there are cases where you'd want to use it (like a method having arguments named the same thing as class variables) |
| All times are GMT -5. The time now is 10:37. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi