PRASHNIKAप्रश्निका
Back to the paper

Consider the following code statement: public class Person { int age; public Person (int age) {…

Computer Science20251 markMCQ
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

AI

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.
Methods

From ISC 2025 Computer Science Paper 1, question 1(v).