Q2: Considering the following incomplete class definition, which of the following constructors can be added to the SomeClass class without causing a compiler error?
public class SomeClass {
public SomeClass(int first ) {
/* implementation not shown */ }
public SomeClass(int first, int second) {
/* implementation not shown */ }
public someClass(int first, String second) {
/* implementation not shown */ }
} // end SomeClass
public class SomeClass {
private int num;
SomeClass (int n) {
num = n;
}
public void increment (int more) {
num = num + more;
}
public int getNum() {
return num;
}
}
The following code segment appears in another class. What is the resulting output?
SomeClass one = new SomeClass(100);
SomeClass two = new SomeClass(100);
SomeClass three = one;
one.increment(200);
System.out.println("d d d", one.getNum(), two.getNum(), three.getNum());
Q3: Consider a class with the following instance variables and incomplete method updateAge. Method updateAge should update the instance attributes based on the parameter extraMonths, which represents the number of months to be added to the age. Which of the following code segments could be used to replace /* body of updateAge */ so that the method will work as intended?
private int years; // age of item in years
private int months; // age of item in months, 0 <= months <= 11
// example, item can be 1 year 3 months old
public void updateAge (int extraMonths) { //extraMonths >= 0
/* body of updateAge */
}