225k views
5 votes
Java uses to reference the current object.group of answer choices

A. this
B. that
C. thisObject
C. D. null

User Kaid
by
3.4k points

1 Answer

4 votes

Answer:

B. this

Step-by-step explanation:

In a constructor for example, this.x will refer to the current object's variable(s).

public class Main {

int x;

// Constructor with a parameter

public Main(int x) {

this.x = x;

}

// Call the constructor

public static void main(String[] args) {

Main myObj = new Main(5);

System.out.println("Value of x = " + myObj.x);

}

}

User Olayinka
by
3.1k points