课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Returning data from methods - Java教程
课程: Java Essential Training: Syntax and Structure
Returning data from methods
- [Instructor] Often the role of a method is to perform a task and then return the result of that task. Let's refactor this isUserQualified method to return a boolean value of true or false and have another method notify the user. If a method is going to return a value, it must indicate that in its header. IsUserQualified currently has a return type of void, meaning it does not return anything. Let's change this to boolean. Within the if block, if the conditions are met we can add a statement that returns true. Likewise, if the condition is not met, we can return false. Now let's revisit the main method. When calling a method that returns a value, you can receive that value and store it into a variable although this is not required. We've already done this without even knowing it. On line 18, we call it the next double method and stored it's return value into the actual salary variable. Let's do same when calling…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。