Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 547 Bytes

File metadata and controls

30 lines (23 loc) · 547 Bytes

Field Initialization

You can set an initial value for a field in a few ways.

One is to assign the field directly on the instance created.

class Muppet {
    String name;
}

void main() {
    Muppet kermit = new Muppet();
    kermit.name = "Kermit The Frog";
}

Another is to set a default value directly in the field declaration. This makes the most sense if its a value that most instances will share.

class Muppet {
    // Most are!
    boolean talented = true;
}

void main() {
    Muppet kermit = new Muppet();
}