LockOn
LockOn

Reputation: 309

value of the parameter of a method

What will be the value of the parameter i.e. private static boolean ask(int i){int te = 8 + i;} Coz i notice the 'i' was use in the method. I just wonder what will be the value of that 'i' and/or what's the use of it?

Upvotes: 2

Views: 98

Answers (2)

Redlab
Redlab

Reputation: 3118

value of te will be 8 + value of i but it will not compile since there is a missing return statement and the method says a boolean is returned

Upvotes: 1

Andrzej Doyle
Andrzej Doyle

Reputation: 103797

The value of i will be whatever the caller of the method passed into the method call.

So if someone called

ask(5);

then i will be 5 within that specific invocation. Parameter values are specific to the particular invocation of the method, must be supplied each time and will be evaluated anew each time. Even if multiple threads are calling the method simultaneously, each will see the value of i that they passed in.

Upvotes: 3

Related Questions