Java OCA OCP Practice Question 118

Question

Given:

4. public class Main extends Counter 
5.   public static void main(String[] args) { 
6.     int myGold = 7; 
7.     System.out.println(count(myGold, 6)); 
8.   } 
9. } 
10. class Counter { 
11.   int count(int x, int y) { return x + y; } 
12. } 

What is the result?

  • A. 13
  • B. Compilation fails due to multiple errors
  • C. Compilation fails due to an error on line 6
  • D. Compilation fails due to an error on line 7
  • E. Compilation fails due to an error on line 11


D is correct.

Note

The count() method cannot be invoked from a static context.

A, B, C, and E are incorrect.




PreviousNext

Related