课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Calling methods
- [Instructor] A method is not executed unless it is called. Let's write a program that defines a method to greet a user by name, and then we will call this method from our main method. All methods must be contained within the scope of a class, but it doesn't matter the order that the methods are defined in. For example, here we have the greetUser method after the main method, but it could also exist before the main method. Methods execute in the order in which they are called. The greetUser method prompts a user for their name, and then it reads and stores it inside of this name variable and finally prints a greeting using the name. If we were to run this program, notice, nothing happens. This is because methods only execute if they are called. While the greetUser method is defined, it has not been called. When you run a Java application, the program starts off in the main method. It's the only method that does not…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。