What is a value-returning method? How is it used?

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 11RQ
icon
Related questions
Question

What is a value-returning method? How is it used?

Expert Solution
Step 1

Returning a method value:

When a method completes all the statement(s) in the method, a return statement is reached or an exception is made, whichever happens first.

In its method statement you declare the return type of a method. The return statement is used for returning the value in the body of the process.

No interest is returned by any process deemed void. It does not have to contain a declaration of return, but does. In this case, a return statement may be used to branch out from and exit the process from a control flow block:

return;

You will receive a compiler error if you are attempting to return a value from a declared null path.

Any process that is not declared void must contain a return statement, like this:

return return value;

The return value data type must conform to the form declared for the method; from the declared method to return a boolean, you can't return the integer value.

Step 2

Uses of Return Value Method:

1.      You declare the return type of a method in its method declaration. For returning the value in the process, the return statement is used. No value is retrieved and no return statement is included in any declared vacuums system. Any non-declared method should contain a return statement.

public boolean isFree()

{

if (items.size() == 0)

       return true; 

   }

else

{   

     return false;

    }

}

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning