When the keyword cannot be used
# Topic
The keyword super
# Problem
When the keyword cannot be used
Given the following class hierarchy, select all illegal usages of the keyword super
:
class A {
protected int a;
}
class B extends A {
protected int b;
public B(int a, int b) {
super(); // 1
super.a = a; // 2
super.b = b; // 3
}
}
class C extends B {
protected int c;
public C(int a, int b) {
super(a); // 4
}
public C(int a) {
super(a, 10); // 5
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Select one or more options from the list
[] 1
[] 2
[x] 3
[x] 4
[] 5
1
2
3
4
5
2
3
4
5
Correct.
# Hint & Explain
Check whether the parent has the same type/number of parameterized constructors or not.
编辑 (opens new window)
上次更新: 2022/09/25, 10:41:23