Question 31
MediumWhat is the output of this program?
public class Main {
{
System.out.println( + + );
}
}
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 {
{
System.out.println( + + );
}
}
21
12
Error
3
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(1 + 2 + "");
}
}
12
Error
Sign up free to see the answer and a step-by-step explanation.
Why are Java Strings immutable?
For security, thread-safety and to allow safe sharing in the string pool
To make concatenation faster
Because Java has no mutable objects
To use less memory per character
Sign up free to see the answer and a step-by-step explanation.
What is the difference between ArrayList and LinkedList in Java?
ArrayList gives O(1) random access; LinkedList gives O(1) insertion/removal at a known position but O(n) access
ArrayList can't grow
LinkedList is always faster
They are identical
Sign up free to see the answer and a step-by-step explanation.
What does the static keyword on a method mean in Java?
The method can't be changed
The method is private
The method runs faster
The method belongs to the class and can be called without an object
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 a = "hello";
String b = "hello";
String c = new String("hello");
System.out.println((a == b) + " " + (a == c) + " " + a.equals(c));
}
}
false false true
true false true
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 = 5;
x = x++ + ++x;
System.out.println(x);
}
}
10
11
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("abc");
sb.append("de").reverse().insert(0, "X");
System.out.println(sb);
}
}
edcbaX
abcdeX
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 = {1, 2, 3};
System.out.println((a == b) + " " + a.equals(b) + " " + java.util.Arrays.equals(a, b));
}
}
true true true
false false true
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[] arr = {3, 1, 2};
int[] copy = arr;
copy[0] = 9;
System.out.println(arr[0] + arr.length);
}
}
12
4
Sign up free to see the answer and a step-by-step explanation.
21
3
true true true
true false false
13
12
Xabcde
Xedcba
false false false
false true true
6
93