COMP 202 Lecture Notes - Lecture 8: Return Statement
jc123 and 40170 others unlocked
100
COMP 202 Full Course Notes
Verified Note
100 documents
Document Summary
Printing and returning are not the same thing! A method returns something when the method call evaluates to a value that can be used in an expression. When a method prints something, it just displays text for the user to read. The method call does not evaluate to a value that can be used in an expression. When you have 2 methods in one class, to make your second method work, you need to call it in the main method to make it do something. See example code on mycourses that creates a method that takes no input and returns nothing, just prints. When a program runs, by default only the main method executes. Other methods only execute if they are called from the main method (or from a method that was called by the main method). Generally, inside of a method, all statements are executed from top to bottom. Methods can be called within other methods.