Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/java-class-data-members
Question 65 / 297:  What is the result of compiling and running the following code?
public class Tester {

static {

int x = 3;

}

static int x;

public static void main(String[] args) {

x--; // line 7

System.out.println(x);

}

}

A  3
B  2
C  -1
D  Compilation error at line 7, x is not initialized
<< First < Previous Next > Last >>
Explanation:

There are two different variables with the same name x, one is declared in the static block and the other is the static variable x which is first initialized with 0 . x used in main() is the the static variable x.

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

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Eric Crawford
Start Quiz
Prateek Ashtikar
Start Quiz
Lakeima Roberts
Start Quiz
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>