Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 721 Bytes

File metadata and controls

34 lines (27 loc) · 721 Bytes

Reassignment

After a variable is declared and assigned an initial value, that value can be later reassigned.

void main() {
    String boss = "Jaqueline";
    IO.println(boss);
    boss = "Chelsea";
    IO.println(boss);
}

Reassignments just involve the name and the new value. The type should not be redeclared.

    boss = "Chelsea";
//  name   new value

After a variable is reassigned, the value associated with the name will reflect the new value from that point in the program onwards.

void main() {
    String boss = "Jaqueline";
    // This will output "Jaqueline"
    IO.println(boss);
    boss = "Chelsea";
    // But this will output "Chelsea"
    IO.println(boss);
}