MOCK TEST DAY1 Fundamentals
MOCK TEST DAY1 Fundamentals
byte x = 5;
byte y = 10;
_____ z = x + y;
A. int
B. long
C. boolean
D. double
E. short
F. byte
2. Given that a Date class exists in both the java.util and java.sql packages, what
is the result of compiling the following class?
1: import java.util.*;
2: import java.sql.*;
3: public class BirthdayManager {
4: private Date rob = new Date(12/3/20);
5: private java.util.Date sharon =new java.util.Date();
6: }
3: int x = 4;
4: long y = x * 4 - x++;
5: if(y<10) System.out.println("Too Low");
6: else System.out.println("Just right");
7: else System.out.println("Too High");
A. Too Low
B. Just Right
C. Too High
D. Compiles but throws a NullPointerException.
E. The code will not compile because of line 6.
F. The code will not compile because of line 7.
4. What is the output of the following code snippet?
3: int y = 1;
4: do{
5: System.out.print(y++ + " ");
6: } while(y == 10);
A. 2 3 4 5 6 7 8 9
B. 1 2 3 4 5 6 7 8 9 10
C. 1
D. The code will not compile because of line 6.
E. The code contains an infinite loop and does not terminate.
A. p1
B. p2
C. p3
D. p4
package dinosaur;
public class Park {
public final static void main(String... arguments) {
int pterodactyl = 3;
long triceratops = 5;
if(pterodactyl % 3 >= 1)
triceratops++;
triceratops--;
System.out.print(triceratops);
}
A. 2
B. 3
C. 4
D.5
E. The code does not compile.
package schedule;
public class PrintWeek {
public static final void main(String[] days) {
System.out.print(5+ “6”+ "7" + 8 + 9);
}
}
A. 56789
B. 11789
C. 51317
D. The code does not compile.
A. Six
B. Seven
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
11. Given
String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello");
System.out.println(s1==s2);
System.out.println(s1==s3);
What is output ?
A. true false
B. false true
C. true false true
D. false true false
E.Code will not compile
12. Given
A. 9
B. 11
C. 12
D. 15
E. The code does not compile.
F. None of the above.
A. x1
B. x2
C. x3
D. None of the above
14. Given
String x1 = "Java";
StringBuilder x2 = new StringBuilder("Java");
String x3 = "Java";
System.out.println(x1==x2);
System.out.println(x1==x3);
What is output ?
A. true true
B. false false
C. true false
D. false true
E. Code will not compile.
var sb = new
StringBuilder("radical").insert(sb.length(), "robots");
System.out.println(sb);
A. radicarobots
B. radicalrobots
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
16.
17.
Given the file Test.java shown, which of the marked lines can you independently
insert the line var x; into and still have the code compile?
// line 1
public class Test{
// line 2
public void attach() {
// line 3
}
// line 4
}
A. line 2
B. line 3
C. line 2 and line 3
D. line 1, line 2,line 3 and line 4
E. None of the above
18.
Which of the following iterates a different number of times than the others?
A. for (int k=0; k < 5; k++) {}
B.
C.
for (int k=1; k <= 5; k++) {}
int k=0; do { } while (k++ < 5);
D. int k=0; while (k++ < 5) {}
E. All of these iterate the same number of times.
A. Option A
B. Option B
C. Option C
D. Option D
E. Options E
19.
The code contains six pairs of curly braces. How many pairs can be
removed without chang- ing the behavior?
12: public static void main(String[] args) {
13:
int secret = 0;
for (int i = 0; i < 10; i++) {
while (i < 10) {
if (i == 5) {
} else {
System.out.println("if");
System.out.println("in");
System.out.println("else");
14:
15:
16:
17:
18:
19:
20:
21:
}
22:
}
23:
}
24:
switch (secret) {
25:
case 0:
26:
}
27: }
System.out.println("zero");
A. One
B. Two
C. Three
D. Four
E. Five
F. Six
20.
Which of these code snippets behaves differently from the others?
A.
if (numChipmunks == 1)
System.out.println("One chipmunk");
if (numChipmunks == 2)
System.out.println("Two chipmunks");
if (numChipmunks == 3)
B.
System.out.println("Three chipmunks");
switch (numChipmunks) {
System.out.println("One chipmunk"); System.out.println("Two chipmunks");
case 3: System.out.println("Three chipmunks");
}
C.
if (numChipmunks
== 1)
System.out.println("One chipmunk");
else if (numChipmunks
==
2)
System.out.println("Two chipmunks");
else if (numChipmunks == 3)
System.out.println("Three chipmunks");
D. All three code snippets do the same thing.
A. Option A
B. Option B
C. Option C
D. Option D