forked from mhussainshah1/SafariJava11Cert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestions.txt
351 lines (275 loc) · 7.58 KB
/
Questions.txt
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
Q1) Given:
public void x() {
var x;
}
What is the result?
A) Compilation fails
B) Exception at runtime
C) x is an int with value zero
D) x is an Object ref with value null
E) x is an Object ref with undefined value
Q2) Given:
public void x() {
var x = 99;
x = "Hello";
}
What is the result?
A) Compilation fails
B) Exception at runtime
C) x becomes "Hello"
D) x remains 99
Q3) Given:
public void x(var x) {
x = "Hello";
}
What is the result?
A) Compilation fails
B) Exception at runtime
C) x becomes "Hello"
Q4) Given:
StringBuilder sb1 = new StringBuilder("Hello World");
String s1 = "Hello World";
sout...(s1.equals(sb1));
What is the result?
A) Compilation fails
B) true
C) false
D) Exception
Q5) Given:
StringBuilder sb1 = new StringBuilder("Hello World");
StringBuilder sb2 = new StringBuilder("Hello World");
sout...(sb2.equals(sb1));
What is the result?
A) Compilation fails
B) true
C) false
D) Exception
Q5) Given:
StringBuilder sb1 = new StringBuilder("Hello World");
StringBuilder sb2 = new StringBuilder("Hello World");
sout...(sb2.equals(sb1));
What is the result?
A) Compilation fails
B) true
C) false
D) Exception
Q6) Given
short s1 = 99;
short s2 = 300;
(trueFunction()) ? s1 : s2
Which are true?
A) The type of the expression is int
B) The type of the expression is short
C) The value of the expression is 300
D) The value of the expression is 99
E) The expression would fail to compile
Q7) Given:
int x = 99;
switch(x) {
case 99: sout("ninetynine");
case 100: sout(100);
}
What is the result?
A) Compilation fails because there is no "default" clause
B) ninetynine
C) No output
D) ninetynine
100
E) Runtime exception
Q8) Given:
switch (x) {
}
Which are valid types for "x":
A) short
B) int
C) long
D) enum
E) StringBuilder
Q9) Given:
int x = 3;
int y = 0;
outer: while (x < 10) {
x = y++;
inner: while(y < 2) {
if (++x > 2) {
//continue outer; // line n1
break inner;
}
}
// nothing here..
}
Which is true?
A) the output is lkjsdlkfjlsdkj
B) the output is lkjasfkljsd
C) if line n1 were replaced with break inner, the output would be unchanged.
Q10) Given:
try {
FileReader fr = ...
// file reading operations...
} catch (IOException ioe) {
} finally {
fr.close();
}
Which are true?
A) The file fr is closed, only if code succeed, or an IOException is thrown
B) The file fr is close, only if the code succeeds or a non-IOException is thrown
C) The file fr is always closed
D) The file fr is never closed
Q21) Given:
public class Scr {
static int x = -1;
public static void main(String[] args) { new ScrSub().doStuff(); }
}
and:
class ScrSub extends Scr {
int x = 99;
void doStuff() {
System.out.print(x + ","); // line n1
int x = 100;
System.out.print(x + ",");
System.out.print(Scr.x + ",");
}
}
What is the result?
A) Compilation fails at line n1
B) Exception at line n1
C) 99, 100, -1
D) 0, 100, 99
E) 0, 100, -1
Q22) Given:
void doStuff(int x, long y) { sout...("v1"); }
void doStuff(long x, long y) { sout...("v2"); }
void doStuff(String x, long y) { sout...("v3"); }
and:
doStuff(1, 1);
What is the result?
A) Compilation fails
B) Exception
C) v1
D) v2
E) v3
Q23) Given:
class MyClass {
private int x = 99;
}
what is the visibility of x?
A) Invisible
B) Compilation error
C) Only in the class/objects MyClass
D) Inside the curly braces
E) Inside the class and the package
Q24) Which are legal (individually):
No A) Predicate<Student> sc = Student s -> { return s.getGpa() > 3;};
No B) Predicate<Student> sc = s -> { s.getGpa() > 3 };
No C) Object sc = s -> {return s.getGpa() > 3;};
Yes D) Predicate<Student> sc = (s) -> s.getGpa() > 3;
No E) Predicate<Student> sc = s -> s.getCourses().size();
Q25) Which are legal individually:
No A) Function<String, String> fss = s -> { System.out.println(s); };
Yes B) Consumer<String> cs = s -> { System.out.println(s); };
No C) Supplier<String> ss = (s1, s2) -> s1 + s2;
No D) BiPredicate<String> bps = (String s) -> { return s.length() > 0; };
Yes E) ToIntFunction<String> tofs = s -> s.length();
--------------------------------
Given:
class Base {
void doBaseStuff() { System.out.println("doBaseStuff"); }
}
class Sub extends Base {
void doBaseStuff() { System.out.println("doSubStuff"); }
void doOtherStuff() { System.out.println("doOtherStuff"); }
}
Q26) and:
Base b = new Base();
Sub s = (Sub)b;
s.doOtherStuff();
What is the result?
A) doSubStuff
B) doOtherStuff
C) doBaseStuff
D) Exception at runtime
E) Compilation failure
Q27)
class Base {
void doBaseStuff() { System.out.println("doBaseStuff"); }
}
class Sub extends Base {
void doBaseStuff() { System.out.println("doSubStuff"); }
void doOtherStuff() { System.out.println("doOtherStuff"); }
}
In the Base and Sub classes, which are true in isolation?
A) doBaseStuff in Base can be marked public without causing errors
B) doBaseStuff in Base can be marked private without causing errors
C) doBaseStuff in Sub can be marked public without causing errors
D) doBaseStuff in Sub can be marked protected without causing errors
E) doBaseStuff in Sub can be marked private without causing errors
Q28)
class Base {
void doBaseStuff() { System.out.println("doBaseStuff"); }
}
class Sub extends Base {
void doBaseStuff() { System.out.println("doSubStuff"); }
void doOtherStuff() { System.out.println("doOtherStuff"); }
}
In the Base and Sub classes, which are true in isolation?
A) doBaseStuff in Base can be marked throws Exception without causing errors
B) doBaseStuff in Base can be marked throws RuntimeException without causing errors
C) doBaseStuff in Sub can be marked throws Exception without causing errors
D) doBaseStuff in Sub can be marked throws RuntimeException without causing errors
E) if doBaseStuff in Base were marked throws Exception,
then doBaseStuff in Sub can be marked throws IOException without causing errors
Q29)
Given:
class Base {
Base doBaseStuff() { return null; }
}
class Sub extends Base {
}
Which may be added individually to the class Sub?
A) Base doBaseStuff() { return null; }
B) int doBaseStuff(int x) { return x * 2; }
C) Sub doBaseStuff() { return null; }
D) CharSequence doBaseStuff() { return null; }
E) Sub doBaseStuff() { return null; }
Q30)
Given:
class Base {
int doBaseStuff() { return 0; }
}
class Sub extends Base {
}
Which may be added individually to the class Sub?
A) int doBaseStuff() { return 0; }
B) long doBaseStuff() { return x * 2; }
C) Sub doBaseStuff() { return null; }
D) short doBaseStuff() { return (short)2; }
E) Sub doBaseStuff() { return null; }
Q31)
StringBuilder sb1 = new StringBuilder("Hello");
StringBuilder sb2 = sb1;
sb1 = null;
Which is true?
A) sb1 is unreferenced and eligible for GC
B) sb1 and sb2 are unreferenced and eligible for GC
C) No objects are eligible for GC
Q32)
StringBuilder sb1 = new StringBuilder("Hello");
StringBuilder sb2 = new StringBuilder("World");
sb1 = null;
sb2 = sb1;
Which is true?
A) Object containing "Hello" is unreferenced and eligible for GC
B) Object containing "World" is unreferenced and eligible for GC
C) Object containing "Hello", and "World" are both unreferenced and eligible for GC
D) No objects are eligible for GC
Q33)
Given:
module first {
exports my.stuff;
}
Which would allow module second to use class my.stuff.Banana
A) module second { requires my.stuff; }
B) module second { requires Banana; }
C) module second { uses my.stuff.Banana; }
D) module second { requires first; }
E) module second { opens first; }