Describe the role of the this keyword
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.
You can using this keyword with a field and also with the constructor.
The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.
From within a constructor, you can also use the this keyword to call another constructor in the same class. Doing so is called an explicit constructor invocation.
Remarks
Text provided above does not means is the
model answer, and it's was posted here for an reference to somebody who
interested the related knowledge only. if there is something incorrect,
please leave a comment so that i can correct it or for others viewer to
have an better reference, if you want know more about this topic and
where is the question, concept or answer from, you can reference from
information provided under the reference sub-title.
Reference:
1) Introduction to Java Programming, Y. Daniel Liang
2) https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
No comments :
Post a Comment