How unicode characters are read in java comments

java, unicode

Solution

Before compilation every Unicode character is replaced by its value and since `\u000a` represents new line code

// String st4="MN3444\u000ar4t4";

is same as this code (notice that text after `\u000a` will be moved to new line, which means it will no longer be part of commented)

// String st4="MN3444
r4t4";

You can test it with

//\u000a;System.out.println("hello comment");

which is equal to

//
System.out.println("hello comment");

and will give you as result output: `hello comment`

Problem

``` class Why { public static void main(String[]s) { String st2="A"; System.out.println(st2); // String st4="MN3444\u000ar4t4"; System.out.println(st4); } } ``` please compile the above code, i am getting the error in the comment line. I am unable to understand this behaviour of the compiler, and what does this error mean ?

Original source

Related problems