Question: Question 8 Given: 3. public class Ouch { 4. static int ouch = 7; 5. public static void main(String[] args) { 6. new Ouch().go(ouch); 7.
Question 8
Given: 3. public class Ouch { 4. static int ouch = 7; 5. public static void main(String[] args) { 6. new Ouch().go(ouch); 7. System.out.print(" " + ouch); 8. } 9. void go(int ouch) { 10. ouch++; 11. for(int ouch = 3; ouch < 6; ouch++) 12. ; 13. System.out.print(" " + ouch); 14. } 15. }
What is the result?
A. 5 7
B. 5 8
C. 8 7
D. 8 8
E. Compilation fails
F. An exception is thrown at runtime
Answer :
E is correct. The parameter declared on line 9 is valid (although ugly), but the variable name ouch cannot be declared again on line 11 in the same scope as the declaration on line 9. A, B, C, D, and F are incorrect based on the above. (OCA Objectives 1.1, 2.1, and 2.5)
Required:
please explain why answer is correct and why not? please explain
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
