1/10
Flashcards about 'this' and 'super' keywords in Java, covering their common uses and syntax.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What does the 'this' keyword refer to in Java?
Refers to the current object of a class.
What is a common use of the 'this' keyword?
To refer to the current class instance variable.
What is another common use of the 'this' keyword?
To invoke the current class constructor.
What is a third common use of the 'this' keyword?
To invoke the current class method.
What is the purpose of the 'this()' keyword?
Used to call another constructor in the same class; known as constructor chaining.
What are the benefits of using 'this()' for constructor chaining?
It helps reuse constructor logic and reduces code duplication.
What is a crucial rule regarding the placement of 'this()' in a constructor?
Must be the first statement in the constructor.
What does the 'super' keyword refer to?
Refers to the parent class (superclass) of the current object.
What is a common use of the 'super' keyword?
To access superclass variables.
What is another common use of the 'super' keyword?
To call superclass methods.
What is a third common use of the 'super' keyword?
To call superclass constructor.