public class Solution {
public static class Idea {
public String getDescription()
{
return "s";
}
}
public static void printIdea(Idea idea)
{
System.out.println(idea.getDescription());
}
public static void main(String[] args) {
printIdea(new Idea());
}
}
I took help from another answer to this question to solve my problem but I would like to how it works in simple terms. Thank you!
hidden #10462592
Level 8
Although it worked, I am not sure what happened here! please explain!
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
17 October 2019, 18:40
Step one, when the program is started the main() method is called.
Step 2: In the main method printIdea() is called with the argument new Idea() (a new Idea object)
Step 3: Code goes to the method printIdea, which accepts as an argument (Idea idea) (an Idea object to be referred to as idea in the subsequent code)
Step 4: inside the printIdea() method, the println() method is called with an argument of (idea.getDescription()), which is the method getDescription defined in Idea class that is called on the object 'idea'
Step 5: code goes to the getDescription() method, which returns a string "s". This method concludes
Step 6: code returns to the printIdea() method and the argument inside the println() method now equals "s", this is output to screen. Method concludes
Step 7: Code returns to the main method, where no more code exists to run, program ends
+3
hidden #10462592
18 October 2019, 05:19
You make it sound simple!! thank you.. I understand now :)
+1