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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education