Question: Consider the following application: what value is printed at line 6?
 


Question: Consider the following application:

1. class Q6 {
2. public static void main(String args[]){
3. Holder h = new Holder();
4. h.held = 100;
5. h.bump(h);
6. System.out.println(h.held);
7. }
8. }
9.
10. class Holder {
11. public int held;
12. public void bump(Holder theHolder){theHolder.held++;}
13. }
What value is printed out at line 6?

A. 0.

B. 1.

C. 100.

D. 101.

Answer:D is correct. A holder is constructed on line 6. A reference to that holder is passed into method bump() on line 5. Within the method call, the holder's held variable is bumped from 100 to 101.

 

 

 

 

 
 
 
 
 
COPYRIGHT © 2017 java-samples.com. ALL RIGHTS RESERVED.