A method is declared as: public void setAge(int age) { this.age = age; } Which statement is correct about this code assuming the class has an instance variable age?
Uses 'this.age' to refer to instance variable.
Why this answer
Option C is correct because the method `setAge(int age)` uses the `this` keyword to assign the parameter value to the instance variable `age`, which is a standard setter pattern in Java. The method has a `void` return type and is not a constructor, and it compiles successfully because the instance variable `age` is assumed to exist in the class.
Exam trap
Oracle often tests the distinction between constructors and regular methods by including a `void` return type, which immediately disqualifies a method from being a constructor, even if it looks like one due to parameter assignment.
How to eliminate wrong answers
Option A is wrong because a constructor must have the same name as the class and no return type, not even `void`; this method has a return type of `void` and is named `setAge`, not matching the class name. Option B is wrong because the code compiles without error as long as the class has an instance variable named `age`; the `this` keyword correctly disambiguates the parameter from the instance variable. Option D is wrong because the method is not declared with the `static` keyword, so it is an instance method that operates on the current object's state.