36.5k views
1 vote
Assume that you have created a class named Dog that contains a data field named weight and an instance method named setWeight(). Further assume that the setWeight() method accepts a numeric parameter named weight. Which of the following statements correctly sets a Dog's weight within the setWeight() method?a. weight = weight

b. this.weight = this.weight
c. weight = this.weight
d. this.weight = weight

User Gary Gauh
by
6.6k points

1 Answer

3 votes

Answer:

D) this.weight = weight

Step-by-step explanation:

since a constructor call in java sets the initial value for variable, using the this.

in this way, refers to the current object in a method or constructor.

User Primusa
by
6.5k points