Why 4? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why 4?

Why answer is 4 instead of 16?

23rd May 2017, 12:20 PM
Dias Zacharias
Dias Zacharias - avatar
3 Answers
0
because 4 instead of 16 too easy non mais allo quoi
23rd May 2017, 12:29 PM
MBZH31
MBZH31 - avatar
0
Because... when the code is compiled JVM looks at main method first and x was already defined as 4 and in square method new variable x was again created in its parameter whose value is 4 and System.out.println does it work afterwards. Method doesn't execute at all.
16th Oct 2017, 8:49 PM
Simon