Question 61
HardWhat is the output of this program?
public class Main {
{
;
+ ;
().intern();
;
part + ;
System.out.println((s1 == s2) + + (s1 == s3) + + (s1 == s4));
}
}
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
public class Main {
{
;
+ ;
().intern();
;
part + ;
System.out.println((s1 == s2) + + (s1 == s3) + + (s1 == s4));
}
}
true true false
true true true
false true false
true false false
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
int[] a = {1, 2, 3};
int[] b = a.clone();
b[0] = 9;
int[][] m = {{1, 2}, {3, 4}};
int[][] n = m.clone();
n[0][0] = 9;
System.out.println(a[0] + " " + m[0][0]);
}
}
1 9
1 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) sb.append(i);
else sb.insert(0, i);
}
System.out.println(sb);
}
}
01234
13024
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
int x = 10;
x += x++ + ++x;
System.out.println(x);
}
}
30
33
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
long big = Integer.MAX_VALUE + 1;
long ok = Integer.MAX_VALUE + 1L;
System.out.println(big + " " + ok);
}
}
2147483648 2147483648
-2147483648 -2147483648
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
System.out.println(10 / 3 + " " + 10 % 3 + " " + -10 / 3 + " " + -10 % 3 + " " + 10.0 / 4);
}
}
3.33 1 -3 -1 2.5
3 1 -4 2 2.5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
java.util.List<Integer> list = new java.util.ArrayList<>(java.util.List.of(10, 20, 30));
list.remove(Integer.valueOf(10));
list.remove(0);
System.out.println(list);
}
}
[]
[30]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
char c = 'A';
c += 1;
int i = c + 1;
char d = (char) (c + 2);
System.out.println(c + "" + i + d);
}
}
6667D
B66C
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
public class Main {
public static void main(String[] args) {
String s = null;
System.out.println("value: " + s + " " + (s instanceof String));
}
}
NullPointerException
value: null true
Sign up free to see the answer and a step-by-step explanation.
What is the output of: System.out.println(0.1 + 0.2 == 0.3);
true
false
0.3
Compilation error
Sign up free to see the answer and a step-by-step explanation.
9 1
9 9
02413
31024
32
31
-2147483648 2147483648
Compilation error
3 1 -3 2 2
3 1 -3 -1 2.5
[20, 30]
[10, 30]
B67D
C67D
value: null false
value: false