Why does Java allow two variables with the same name to be declared in the same scope?

Brax :

I am stunned after compiling and executing this program.

String name = "Braxton";
String namе = "Phillippa";
System.out.println(name); //Braxton
System.out.println(namе); //Phillippa

It compiles successfully and executes fine. What is wrong with java?

Sam :

This happens because e and е appears same but are different unicode characters. You can verify this by copy pasting the above letters into What Unicode character is this.

System.out.println("\u0065");
System.out.println("\u0435");

Note: To reproduce the above problem you have to copy paste the code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=317056&siteId=1