Java · Question 4 · Easy
What will be the output of the following Java program?
public class Main {
public static void main(String[] args) {
char c = 'a';
System.out.println(c + 1);
}
}
- b
- a1
- 98
- Compilation error
Answer and explanation
Answer: C. 98
Explanation: In c + 1 the char is promoted to int, so the result is the int 97 + 1 = 98, and println prints the number, not a character.
Previous: Which Java keyword, when applied to a class, prevents any other class from… · Next: What is the default value of an int instance variable (field) that is declared…
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?
- Which Java keyword, when applied to a class, prevents any other class from…
- What is the default value of an int instance variable (field) that is declared…
- 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?
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