Java Challenge #2: Is It Going to Compile?

Crazy Java Code

Is it going to compile? If not, why? If you think it’s going to compile, what will happen? What will be the output?

Try to solve this challenge before seeing the answer below.

is_it_going_to_compile.jpg

Answer: It is going to compile! You see, the variable can be created with a class name, no problem. We can use the semicolon “;” several times too.

The char array declaration can be done as shown above. Later, maybe in a vector challenge, I can explain what happens when brackets “[]” are put before the variable.

doesthisCompile: Yes again. This command, called label, can be used for controlling external loopings with “continue” or “break” command, for example.

We can use System.out.println on the looping and we don’t have to use a condition in the second part of the “for”.

Written by
Rafael del Nero
Join the discussion

Stand Out as a Java Developer and Get Your Dream Job!

You will get the book by email in a few minutes after registering.