🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Data Types: all 10 questions

Quiz: Java Data Types · Question 4 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        char c = 'a';
        System.out.println(c + 1);
    }
}
  1. A.b
  2. B.98
  3. C.a1
  4. D.Error
Answer & explanation

Correct answer: 98

char + int gives an int: 'a' is 97, so 97 + 1 = 98. Cast to char to get 'b'.

Can you get the rest right without peeking?

Take the timed Quiz: Java Data Types quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →