Docsity

Understanding the Return Statement in Java Programming, Slides of Java Programming

Partial preview of the text

Download Understanding the Return Statement in Java Programming and more Slides Java Programming in PDF only on Docsity!

The Return Statement

What is the return statement?

  • It is a type of statement.
  • The return statement is a control flow statement that terminates the the execution of a method and returns control to it’s caller.
  • The purpose of a control flow statement is to control the flow of execution of a program.
  • It generally should not be more than one line long.

Code Examples

public final int ordinal;

public final String name;

public String toString(){

return name;

Public int getOrdinal(){

return ordinal;

Void type return statement

• Return statements that do not return a value.

  • If the return type of a method is void, no return

statements in the method body may return

values.