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.
Get Free Quote!
441 Experts Online