Java · Question 24 · Medium
What will be the output of the following Java program?
public class Main {
public static void main(String[] args) {
String s = "Mumbai";
System.out.println(s.length() + s.charAt(0));
}
}
- 83
- 77
- 6M
- Compilation error
Answer and explanation
Answer: A. 83
Explanation: Both operands are numeric: length() is 6 and the char 'M' has code 77. With no String operand, + performs addition and gives 83.
Previous: What will be the output of the following Java program? · Next: Which Java collection class does NOT allow duplicate elements and keeps…
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
- Which of the following statements about interfaces is true in Java 8 and later?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- Which Java collection class does NOT allow duplicate elements and keeps…
- 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?
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