Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 998 Bytes

File metadata and controls

44 lines (33 loc) · 998 Bytes

Local Variables

Mechanically, the next thing to cover is "variables".

~IF toplevel_anonymous_class

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

~ELSE

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

~ENDIF

A variable declaration has three components - the "type", the "name", and the "initial value".

     String boss = "Jaqueline";
//   type   name   initial value

In this case, we are declaring a variable called "boss" and assigning it the initial value of "Jaqueline". Its "type" is "String", which I'll explain in more detail a bit ahead.

After you declare a variable and assign it a value, the "name" refers to the value on the right hand side and you can use that name instead of the value.

// Does the same thing as System.out.println("Jaqueline");
String boss = "Jaqueline";
System.out.println(boss);