What is the result of the code?
Anonymous Quiz
24%
Compile error on line 14
8%
Compile error on line 15
21%
Compile error on line 16
7%
Compile error on another line
11%
==
20%
equals
8%
An exception is thrown
Code snippet
List<String> one = new ArrayList<String>();
one.add("abc");
List<String> two = new ArrayList<>();
two.add("abc");
if (one == two)
System.out.println("A");
else if (one.equals(two))
System.out.println("B");
else
System.out.println("C");
What is the result of the code?
Anonymous Quiz
18%
A
42%
B
17%
C
15%
An exception is thrown
9%
The code does not compile
Code snippet:
LocalDate date = LocalDate.parse("2018-04-30", DateTimeFormatter.ISO_LOCAL_
DATE);
date.plusDays(2);
date.plusHours(3);
System.out.println(date.getYear() + " " + date.getMonth() + " "
+ date.getDayOfMonth());
What is the output of the code?
Anonymous Quiz
14%
2018 APRIL 2
27%
2018 APRIL 30
34%
2018 MAY 2
18%
The code does not compile
7%
A runtime exception is thrown
Code snippet
1: package rope;
2: public class Rope {
3: public static int LENGTH = 5;
4: static {
5: LENGTH = 10;
6: }
7: public static void swing() {
8: System.out.print("swing ");
9: }
10: }
1: import rope.*;
2: import static rope.Rope.*;
3: public class Chimp {
4: public static void main(String[] args) {
5: Rope.swing();
6: new Rope().swing();
7: System.out.println(LENGTH);
8: }
9: }
What is the output of the code?
Anonymous Quiz
8%
swing swing 5
41%
swing swing 10
14%
Compiler error on line 2 of Chimp
15%
Compiler error on line 5 of Chimp
17%
Compiler error on line 6 of Chimp
5%
Compiler error on line 7 of Chimp
Code snippet:
import rope.*;
import static rope.Rope.*;
public class RopeSwing {
private static Rope rope1 = new Rope();
private static Rope rope2 = new Rope();
{
System.out.println(rope1.length);
}
public static void main(String[] args) {
rope1.length = 2;
rope2.length = 8;
System.out.println(rope1.length);
}
}
package rope;
public class Rope {
public static int length = 0;
}
What is the output of the code?
Anonymous Quiz
18%
02
16%
08
23%
2
17%
8
18%
The code does not compile
8%
An exception is thrown
Code snippet:
1: public class RopeSwing {
2: private static final String leftRope;
3: private static final String rightRope;
4: private static final String bench;
5: private static final String name = "name";
6: static {
7: leftRope = "left";
8: rightRope = "right";
9: }
10: static {
11: name = "name";
12: rightRope = "right";
13: }
14: public static void main(String[] args) {
15: bench = "bench";
16: }
17: }
How many compiler errors are in the following code?
Anonymous Quiz
14%
0
13%
1
19%
2
25%
3
18%
4
12%
5
Code snippet
1: public class Test {
2: public void print(byte x) {
3: System.out.print("byte");
4: }
5: public void print(int x) {
6: System.out.print("int");
7: }
8: public void print(float x) {
9: System.out.print("float");
10: }
11: public void print(Object x) {
12: System.out.print("Object");
13: }
14: public static void main(String[] args) {
15: Test t = new Test();
16: short s = 123;
17: t.print(s);
18: t.print(true);
19: t.print(6.789);
20: }
21: }
What is the result of the statements?
Anonymous Quiz
11%
bytefloatObject
14%
intfloatObject
21%
byteObjectfloat
36%
intObjectfloat
16%
intObjectObject
2%
byteObjectObject
Code snippet:
1: public class Squares {
2: public static long square(int x) {
3: long y = x * (long) x;
4: x = -1;
5: return y;
6: }
7: public static void main(String[] args) {
8: int value = 9;
9: long result = square(value);
10: System.out.println(value);
11: } }
What is the result of the program?
Anonymous Quiz
10%
-1
34%
9
31%
81
16%
Compiler error on line 9
9%
Compiler error on a different line
Code snippet:
public class BirdSeed {
private int numberBags;
boolean call;
public BirdSeed() {
// LINE 1
call = false;
// LINE 2
}
public BirdSeed(int numberBags) {
this.numberBags = numberBags;
}
public static void main(String[] args) {
BirdSeed seed = new BirdSeed();
System.out.println(seed.numberBags);
} }
Which code can be inserted to have the code print 2?
Anonymous Quiz
17%
Replace line 1 with BirdSeed(2);
17%
Replace line 2 with BirdSeed(2);
14%
Replace line 1 with new BirdSeed(2);
21%
Replace line 2 with new BirdSeed(2);
24%
Replace line 1 with this(2);
7%
Replace line 2 with this(2);
Code snippet:
public class Cheetah {
int numSpots;
public Cheetah(int numSpots) {
// INSERT CODE HERE
}
public static void main(String[] args) {
System.out.println(new Cheetah(50).numSpots);
}
}
Which of the following complete the constructor so that this code prints out 50?
Anonymous Quiz
8%
numSpots = numSpots;
15%
numSpots = this.numSpots;
58%
this.numSpots = numSpots;
6%
numSpots = super.numSpots;
3%
super.numSpots = numSpots;
9%
None of the above