This chapter is from the book
Certification Practice
The following question is the kind of thing you could expect to be asked on a Java programming certification test. Answer it without looking at today’s material or using the Java compiler to test the code.
Given:
public class AyeAye { int i = 40; int j; public AyeAye() { setValue(i++); } void setValue(int inputValue) { int i = 20; j = i + 1; System.out.println("j = " + j); } }
What is the value of the j variable at the time it is displayed inside the setValue() method?
- A. 42
- B. 40
- C. 21
- D. 20
The answer is available on the book’s website at www.java21days.com. Visit the Day 3 page and click the Certification Practice link.