An object is typically created using a constructor and the
ClassName variable = new ClassName(argumentList);
has a field variable named
and a method named
field1 may be accessed as
may be invoked as
Java provides the
keyword to refer to the current object instance
keyword is used within constructors and non-static methods. When
is used within a constructor, it refers to the object being created.
When it is used within a non-
method, it refers to the object whose method is being invoked.
methods are not associated with an instance of a class, you should not use
keyword is similar to
, except that it refers to the superclass of the current object instance.
keyword is used to access field variables and methods of an object's superclass that may have been hidden or overridden by those of the object's class.
The Instance program
illustrates the use of
Within an instance method or a constructor, this is a reference to the current object, the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.