So I was testing some code and here they are:
public class Phone {
String phoneNumber = "1234";
void setNumber(){
String phoneNumber;
phoneNumber = "4321";
}
}
public class TestPhone {
public static void main(String[] args) {
// TODO Auto-generated method stub
Phone p1 = new Phone();
p1.setNumber();
System.out.println(p1.phoneNumber);
}
}
Output:
1234
Why not 4321
? I called setNumber
so phoneNumber
should be assigned to 4321
, what am I missing?