1. What does the following program print?
class ClassOne {
String data = "go";
public String get() {
return data;
}
public String mystery() {
return get()+" team";
}
}
class ClassTwo extends ClassOne {
String other = "home";
public String get() {
return other;
}
}
class OneTwoTest {
public static void main(String[] args) {
ClassOne one = new ClassOne();
ClassTwo two = new ClassTwo();
fiddle(one);
fiddle(two);
}
static void fiddle(ClassOne x) {
System.out.println(x.mystery());
}
}
__________________________________
__________________________________
2. Write a method, rangeBuilder(), that takes two integer parameters m and n. The method should create an array of
integers with n-m+1 elements. You may assume that n is greater than m. Fill the array with the integer values m,
m+1, m+2, ... n and return the filled array. For example if called with rangeBuilder(4,6), the method would return
an array of 3 elements containing 4 at index 0, 5 at index 1, and 6 at index 2.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 1 | 2 |