Crazy Java Code

Java Challenge #2: Is It Going to Compile?

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

Senior Java Interview Questions from Global Companies

Includes detailed answers and practical explanations from real interviews.

Delivered to your email within minutes.