Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 1.32 KB

File metadata and controls

69 lines (55 loc) · 1.32 KB

Reassignment

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

~IF toplevel_anonymous_class

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

~ELSE

public class Main {
    public static void main(String[] args) {
        String boss = "Jaqueline";
        System.out.println(boss);
        boss = "Chelsea"
        System.out.println(boss);
    }
}

~ENDIF

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.

~IF toplevel_anonymous_class

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

~ELSE

public class Main {
    public static void main(String[] args) {
        String boss = "Jaqueline";
        // This will output "Jaqueline"
        System.out.println(boss);
        boss = "Chelsea"
        // But this will output "Chelsea"
        System.out.println(boss);
    }
}

~ENDIF