Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-declare-java-inner-class-inside-a-method
Question 41 / 297:  Are the lines 1 and 2 correct and free of compilation errors?
public class AirPlane {

public void fly(int speed) {

final int e = 1;

class FlyingEquation {

{

System.out.println(e);// line 1

System.out.println(speed);// line 2

}

}

}

}

A  Both statements at lines 1 and 2 are correct
B  Both statements at lines 1 and 2 are incorrect and cause compilation errors
C  Compilation error at line 1 , inner class can't access outer class local variables
D  Compilation error at line 2, inner class can't access method's arguments
<< First < Previous Next > Last >>
Explanation:

An inner class defined inside a method cannot access the method local variables unless these local variables are final

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>