A driver surrenders the old license to the DVM clerk, who invalidates it.
class: [ modifiers ]? class ClassName [ modifiers ]?{
[ declaration ]*}
declaration: instanceVariable | method | constructor
class DriversLicense { // blah blah blah }
old_max_value
, but oldMaxValue
.
method: [ modifiers ]? returnType methodName(
[ arguments ]?) { ... }
arguments: argument [,
argument ]* argument: [ modifiers ]? type argumentName
class DriversLicense { boolean isValid() { ... } void invalidate() { ... } }
constructor: [ modifiers ]? ClassName(
[ arguments ]?) {...}
instanceVariable: [ modifiers ]? type variables;
variables: variable [,
variable ]* variable: variableName [=
initializer ]?
class DriversLicense { String licenseNumber; boolean valid = true; DriversLicense() { ... } boolean isValid() { ... } void invalidate() { ... } }
class: [ modifiers ]? class ClassName [ modifiers ]?{
[ declaration ]*}
declaration: instanceVariable | method | constructor instanceVariable: [ modifiers ]? type variables;
variables: variable [,
variable ]* variable: variableName [=
initializer ]? method: [ modifiers ]? returnType methodName(
[ arguments ]?) { ... }
arguments: argument [,
argument ]* argument: [ modifiers ]? type name constructor: [ modifiers ]? ClassName(
[ arguments ]?) { ... }
classInstance.fieldName
classInstance.methodName(
arg, ...)
this
.
boolean isValid() { this.invalidate(); // stupid return this.valid; }
this.
are omitted.
boolean isValid() { invalidate(); // stupid, but shorter return valid; }
this
Conventionthis.
for instance variable access.
DriversLicense(String licenseNumber) { this.licenseNumber = licenseNumber; } /* or */ DriversLicense(String ln) { licenseNumber = ln; }
class DriversLicense { String licenseNumber; // and so on }
class DriversLicense { boolean valid = true; // and so on. }
class DriversLicense { String licenseNumber; boolean valid = true; DriversLicense(String licenseNumber) { this.licenseNumber = licenseNumber; this.valid = false; } }