Why do two variables have the same name?

I am executing the following code and I am not getting any errors, and on the output I see the message Success! . Could you explain this strange behavior.

 public class Main { public static void main(String[] args) { int  = 0; int p = 1; if( == 0 && p == 1) { System.out.println("Success!"); } } 

You can check out the online demo.

+5
source share
1 answer

both are different variables (but looks similar), you can see that UTF-16 is different

  int  = 0; int p = 1; if ( == 0 && p == 1) { System.out.println("Success!"); System.out.println("p UTF-16 is " + (int) 'p'); System.out.println(" UTF-16 is " + (int) ''); } 

Output

 Success! p UTF-16 is 112  UTF-16 is 1088 
+11
source

Source: https://habr.com/ru/post/1274989/


All Articles