Multiple Choice Question

Quiz Guidelines

 

QID: 
456
Question: 

Consider the following code appearing in the same file:

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 currently referred to by the variable d to contain 2, 2 as values for its data fields?

Select 1 option

A. Add the following two statements :
          d.x = 2;
          d.y = 2;
B. Add the following statement:
           d = new Data(2, 2);
C. Add the following two statements:
        d.x += 1;
         d.y += 1;
D. Add the following method to Data class:
         public void setValues(int x, int y){
         this.x.setInt(x); this.y.setInt(y);
         }
                 Then add the following statement:
                  d.setValues(2, 2);
E. Add the following method to Data class:
           public void setValues(int x, int y){
          this.x = x; this.y = y;
                         }
            Then add the following statement:
                 d.setValues(2, 2);

Q&A Set: 

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!