QUESTION 2
Given:
1. class ClassA {
2. public int numberOfInstances;
3. protected ClassA(int numberOfInstances) {
4. this.numberOfInstances = numberOfInstances;
5. }
6. }
7. public class ExtendedA extends ClassA {
8. private ExtendedA(int numberOfInstances) {
9. super(numberOfInstances);
10. }
11. public static void main(String[] args) {
12. ExtendedA ext = new ExtendedA(420);
13. System.out.print(ext.numberOfInstances);
14. }
15. }
Which statement is true?
A. 420 is the output.
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.
Solution : A
plus imformation :
super : 자신을 가리키는 키워드가 this 라면 부모를 가리키는 키워드는 super
super()는 부모의 생성자를 의미한다.
여기서 부모는 ClassA이다 .
'자격증 > OCJP_ExamB' 카테고리의 다른 글
QUESTION 6 (0) | 2018.07.09 |
---|---|
QUESTION 5 (0) | 2018.07.09 |
QUESTION 4 (0) | 2018.07.09 |
QUESTION 3 (0) | 2018.07.09 |
QUESTION 1 (0) | 2018.07.08 |
#IT #먹방 #전자기기 #일상
#개발 #일상