Call by Value

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Call by Value.

Call by Value

parameter x

 

Java uses call by value for parameter passing, which means that the contents (the value) of a variable is sent to a method when the variable is used as a parameter. The picture shows the review program immediately after the method call.

The value 27 from main()'s variable value has been copied into the parameter x.

QUESTION 4:

If the zero() method now changes x to zero, what happens to value in main()?