1.Suppose that a method has one node as a parameter and it returns two reference
ID: 3545088 • Letter: 1
Question
1.Suppose that a method has one node as a parameter and it returns two references to nodes. What's the best header for the method?
4.
Answer
A. IntNode foo(IntNode p)B. IntNode, IntNode foo(IntNode p)
C. IntNode[ ] foo(IntNode p)
D. void foo(IntNode p, IntNode answer1, IntNode answer2) 2.Here is some code to count the number of occurrences of a specific target integer in an array of integers:
int i;
int answer = 0;
for (i = 0; i < data.length; i++)
if (data[i] == target)
answer++;
At the end of the code, the value of answer indicates how many times target appears in the array.
Rewrite the code so that it works correctly when the data array is an array of objects and target
is a non-null reference to an object with an equals method. 3. Suppose that obj is an Object variable and s is a String variable. Which of the following statements
is a correctly-compiling widening conversion? Don't worry about possible run-time exceptions. Answer A. obj = s;
B. s = obj;
C. s = (String) obj;
D. Two or more answers are correct.
4.
Consider this code using the ArrayBag of Section 5.2 and the Location class from Chapter 2. What is the output?Location i = new Location(0, 3);
Location j = new Location(0, 3);
b.add(i);
b.add(j);
// Change the Location j:
j.shift(1, 0);
System.out.println(b.countOccurrences(i));Answer
A. 0B. 1
C. 2
D. 3
Explanation / Answer
D option
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.