79.5k views
3 votes
Which of the following is an example of using 'this' to send a self-reference to another object?

a) (this)
b) this.setX(xVal)
c) this.setY(yVal)
d) None of the above

1 Answer

7 votes

Final answer:

The correct answer is b) this.setX(xVal). The 'this' keyword is used in object-oriented programming languages, such as Java, to refer to the current instance of a class.

Step-by-step explanation:

The correct answer is b) this.setX(xVal).

The 'this' keyword is used in object-oriented programming languages, such as Java, to refer to the current instance of a class. The example given, this.setX(xVal), demonstrates the use of 'this' to call a method on the current object and pass a value as an argument.

By using 'this' in this context, we are telling the program to invoke the setX method on the current object and pass xVal as its argument.

User Rushi Soni
by
8.6k points