‹ Back to the paper
Question 1(v)
1 mark
Computer ScienceISC 2025 Computer Science Paper 1MCQMethods
Choose the correct option.
Consider the following code statement: public class Person { int age; public Person (int age) {…
Consider the following code statement:
public class Person
{ int age;
public Person (int age)
{
this.age = age;
}
}Which of the following statements are valid for the given code?
I. The keyword this in the constructor refers to the current instance of the class.
II. The keyword this differentiates between the instance variable age and the parameter age.
III. The keyword this can be used only in constructors.- (a)Only I and II
- (b)Only II and III
- (c)Only I and III
- (d)Only III
Answer
Answer
Correct option: (a)
Answer: (a) Only I and II
The keyword 'this' refers to the current object's instance (I is true) and is commonly used to distinguish an instance variable from a parameter of the same name (II is true). However, 'this' can be used in any instance method, not only in constructors, so III is false.