Most likely, both objects were declared locally and not global, otherwise I would not have allowed it.
That is, you have two functions
public void funcion1() {
int numero = 0;
}
public void funcion2() {
int numero = 1;
}
Both functions have the same name, but because they are local they are destroyed when they leave the method, so they only have an impact within the same method. You could also do the same
public void funcion1() {
int numero = 0;
funcion2();
}
public void funcion2() {
int numero = 1;
}
And there would be no problem, the problem would come when you declare a global function and a local with the same name or two local functions with the same name or two global functions with the same name.
The language will not know which variable with that name to point to, some languages like java if it allows you to create local variable and global variable pointing with this.
to the global variable and if it is put without the 'this' it is pointing to the variable local.
private int numero;
public void funcion1() {
int numero = 0;
this.numero = numero //la variable global será igual a la local
}
But no language will allow you to create two local variables or two global variables with the same name.
Remember that most of the language is caseSensitive, it means that they are case-sensitive, not the same%% co% as%% co% or%%%