0
public class OperationExample {
    public static void main(String[] args) {
        char c1 = 'a';

        char c2 = 'a' + 1;
        // char c2 = c1 + 1; <- compile error

        System.out.println(c2);
    }
}

The first statement which declares c2 can be compiled, but the second one cannot be compiled. I heard that the factor for this difference is about literal, but I cannot understand this phenomenon exactly.
Can you give me an explanation for this situation?

user207421
  • 298,294
  • 41
  • 291
  • 462
uhmseohun
  • 9
  • 1
  • There is no [tag:operator-keyword] in your question, or for that matter in Java. Don't tag indiscriminately. – user207421 Jun 05 '22 at 06:31
  • Why add a letter to a number? – ethry Jun 05 '22 at 06:32
  • @user207421 I added it. – uhmseohun Jun 05 '22 at 06:47
  • 1
    Please *don't* add tags that are completely irrelevant to the question. As user207421 noted, *there is no `operator` keyword in Java, so you shouldn't use that as a tag. – Jon Skeet Jun 05 '22 at 06:52
  • You added it why? *After* you had been told it was irrelevant? The [tag:operator-keyword] exists in C++ but not in Java. It is not relevant to this question or this programming language. – user207421 Jun 05 '22 at 07:24

0 Answers0