forked from cirosantilli/java-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperCheat.java
More file actions
64 lines (50 loc) · 1.5 KB
/
SuperCheat.java
File metadata and controls
64 lines (50 loc) · 1.5 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
# super
*/
public class SuperCheat {
public static void main(String[] args) {
/*
Call overriden constructor of superclass:
super()
This is already implicily added if you don't have a super call.
*/
/*
Call overriden method of superclass:
super.method()
TODO possible without repeating the method name?
*/
/*
# super.super
Not possible: http://stackoverflow.com/questions/586363/why-is-super-super-method-not-allowed-in-java
*/
/*
# this() and super() on a single constructor
Not possible:
- http://stackoverflow.com/questions/10381244/why-cant-this-and-super-both-be-used-together-in-a-constructor
- http://stackoverflow.com/questions/6965561/how-to-call-both-super-and-this-in-case-of-overloaded-constructors
*/
{
class Class {
Class() {
super();
//this(1);
}
Class(int i) {}
}
}
/*
Must be the very first statement of the constructor if present.
Consequence: only one super call per class.
*/
{
class Class {
int i;
Class() {
i = 1;
// ERROR: call to super must be the first thing in a constructor.
//super();
}
}
}
}
}