Java offers various "." naming shortcuts, which we like, but they can hide what's going on. So we review them, and where we can use them: What Short Name Full Name Where ------------------- ---------- ---------------- ---------------------- class in a package AClass path.to.AClass anywhere after import static variable aVar AClass.aVar in AClass static method aMethod() AClass.aMethod() in AClass instance variable aVar this.aVar in AClass object scope instance method aMethod() this.aMethod() in AClass object scope More Details: * Note these synonyms: "instance" and "object", "field" and "variable". * The variable name shortcuts can be masked by a parameter or local variable with the same name. You can still use the full name. * "constructors" are special-purpose instance methods, used to initialize an object just created by "new". If we do not define a constructor in our class, Java defines a "default" constructor. * AClass "object scope" means anwhere the implicit "this" is defined. This includes instance methods, constructors, and initializer expressions for instance variables. It does not include static methods or static initializers. Note "this" is never null. |