-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloadTest.java
More file actions
151 lines (127 loc) · 2.27 KB
/
OverloadTest.java
File metadata and controls
151 lines (127 loc) · 2.27 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class OverloadTest {
public static void main(String[] argv) {
Box b = new Box();
b.setX(9);
Overloads o = new Overloads();
System.out.println(o.overload(11));
System.out.println(o.overload(b));
CovarianceTest ct = new CovarianceTest();
CovarianceTestChild ctc = new CovarianceTestChild();
CovarianceTest ct2 = ctc;
Parent p = new Parent();
Child c = new Child();
p.init();
c.init();
System.out.println(0);
ctc.test(c);
ct2.test(c);
System.out.println(0);
ctc.test(p);
ctc.test(c);
System.out.println(0);
ct.testReturn(c);
ctc.testReturn(p);
ctc.testReturn(c);
System.out.println(0);
Fact1 fact1 = new Fact1();
System.out.println(fact1.fact(5));
Fact2 fact2 = new Fact2();
System.out.println(fact2.fact(6));
System.out.println(0);
boolean test;
test = true;
if(test){
System.out.println(1);
} else {
System.out.println(5);
}
System.out.println(0);
boolean x = true;
boolean y = x || false;
if(y){
System.out.println(1);
}
System.out.println(0);
ShortCircuitTest sct = new ShortCircuitTest();
if(sct.print(1, false) && sct.print(2,true) && sct.print(3,true)){
sct.print(4,true);
}
if(sct.print(1, true) || sct.print(2, false)){
sct.print(3, true);
}
}
}
class Overloads {
int overload(int x){
return x;
}
int overload(Box b){
return b.value();
}
}
class Box {
int x;
int value(){
return x;
}
void setX(int arg){
x = arg;
}
}
class Parent {
int x;
void init(){
x = 10;
}
int value(){
return x;
}
}
class Child extends Parent {
void init(){
x = 11;
}
}
class CovarianceTest {
void test(Child p){
System.out.println(p.value());
}
Parent testReturn(Child c){
System.out.println(c.value());
return new Parent();
}
}
class CovarianceTestChild extends CovarianceTest {
void test(Parent p){
System.out.println(p.value());
System.out.println(101);
}
Child testReturn(Parent p){
System.out.println(p.value());
return new Child();
}
}
class Fact1 {
int fact(int x){
if(x == 1){
return 1;
}
return x*this.fact(x-1);
}
}
class Fact2 {
int fact(int x){
int res = 1;
while(x > 1){
res = res * x;
x = x - 1;
}
return res;
}
}
class ShortCircuitTest {
boolean print(int val, boolean x){
System.out.println(val);
return x;
}
}