Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

Doubt - Practice 1 - Question 26

Hi guys! I've just implemented this code in java 8 and the correct answer is letter F. I didn't have any compilation fail. I guess in Java 6 is the same.


Thanks. :)

That is actually a new thing in Java 8. Take a look at what the Oracle docs say about this:


http://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html#accessing-members-of-an-enclosing-class


So, since Java 8, the variable could be "final or effectively final". They define the idea of "effectively final" as "A variable or parameter whose value is never changed after it is initialized is effectively final.".


Since the deck1 variable does not actually get changed in this program, Java 8 can recognize that as an effectively final variable, and proceed with compilation.

ExamLab © 2008 - 2024