I'm not sure what the answer notes are talking about when they say the following:
I know the way they have created the "setInt" method is weird but from the looks of it they are simply creating a method within the "setValues" method and then setting the primitive values of the instance variables x & y to equal whatever int is passed to the method. However they say that you can't call any methods on a primitive so I'm a bit confused. Please helpx is primitive int.You cannot call any methods on a primitive. so this.x.setInt(...) or this.y.setInt(...) don't make any sense.
The Code in question that's calling a method on a primitive is below:
//add the following method to data class:
Code: Select all
public void setValues(int x, int y){
this.x.setInt(x); this.y.setInt(y); }
//Then add the following statement:
d.setValues(2, 2);
Code: Select all
class Data {
private int x = 0, y = 0;
public Data(int x, int y){
this.x = x; this.y = y;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d = new Data(1, 1);
//add code here
}
}
Which of the following options when applied individually will change the Data object referred to by the variable d to contain 2, 2 as values for its data fields?