Challenge: Reference and Local Variables
Read the problem statement carefully and solve the challenge by defining the reference and local variables in the right place.
We'll cover the following
Problem statement
-
Declare a local
private int
type variable, name it mySecretNumber, assign it a value of10
, and declare it outside the functions. -
Inside the
displaySecret
function, reassign the value of45
to mySecretNumber. -
Create a reference variable of
RLVariables
and name it secret. Access the instance variable (mySecretNumber) using reference variable secret with the following line:- Reference variable accessing instance variable: (print the reference variable here)
-
Now print the local variable on the new line:
- Local Variable: (print the local variable here)
-
Assign the local variable value to the instance variable of the reference variable and print the following on the new line:
- Reference variable accessing instance variable that points to the local variable: (print the reference variable here)
Get hands-on with 1400+ tech skills courses.