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);
    }
}
  1. b
  2. a1
  3. 98
  4. 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

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