請問Java的高手,底下的程式會顯示兩行結果,我不懂的是為何第二個結果是1: John而不是2: Mary?在class c的建構子中不是已經將兩變數都改變為第一個結果了嗎?
結果:
2: Mary
1: John
public interface I {
int i = 1;
String name = "John";
void show();
}
public class c implements I {
public c (){
int i = 2;
String name = "Mary";
System.out.println(i+": "+name);
}
@Override
public void show(){
System.out.println(i+": "+name);
}
public static void main(String[] args) {
int i = 3;
String name = "Alan";
c stud = new c();
stud.show();
}
}