Multiple question of Computer science

computer science

Description

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.


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.