Java · Question 9 · Medium
What will be the output of the following Java program?
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("abc");
sb.append("de").reverse();
System.out.println(sb);
}
}
- edcba
- abcde
- cbade
- edc
Answer and explanation
Answer: A. edcba
Explanation: StringBuilder is mutable: append changes sb to "abcde" and reverse() then reverses the same object in place, giving "edcba".
Previous: What will be the output of the following Java program? · Next: What will be the output of the following Java program?
Practise java
Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.
More java questions
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program (default JVM settings)?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- Which of the following is NOT a primitive data type in Java?
More technical & programming practice
Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge