QUESTION 10자격증/OCJP_ExamC2018. 7. 21. 16:55
Table of Contents
반응형
QUESTION 10Click the Exhibit button.1. public class A {2.3. private int counter = 0;4.5. public static int getInstanceCount(){6. return counter;7. }8.9. public A(){10. counter++;11. }12. }13.Given this code from Class B:A a1 = new A();A a2 = new A();A a3 = new A();System.out.println(A.getInstanceCount());What is the result?A. Compilation of class A fails.B. Line 28 prints the value 3 to System.out.C. Line 28 prints the value 1 to System.out.D. A runtime error occurs when line 25 executes.E. Compilation fails because of an error on line 28.Solution : A
plus imformation
Main.java:6: non-static variable counter cannot be referenced from a static context
return counter;
^
1 error
반응형
'자격증 > OCJP_ExamC' 카테고리의 다른 글
QUESTION 12 (0) | 2018.07.21 |
---|---|
QUESTION 11 (0) | 2018.07.21 |
QUESTION 9 (0) | 2018.07.21 |
QUESTION 8 (0) | 2018.07.21 |
QUESTION 7 (0) | 2018.07.21 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상