Question: 1 0 . In the following code an integer array is passed to a function that attempts to exchange its first two elements. Do the

10. In the following code an integer array is passed to a function that attempts to exchange its first two
elements. Do the elements get exchanged? If not, why not?
int[] array1={1,2,3,4,5};
exchangeInts(array1);
System.out.println(array1[0]);
System.out.println(array1[1]);
...
public void exchangeInts(int[] array1)
{
int temp;
temp = array1[0];
array1[0]=array1[1];
array1[1]=temp;
}
11. In the following code a String array is passed to a function that attempts to exchange its first two
Strings. Do the elements get exchanged? If not, why not?
String[] array1={"one","two","three","four","five"};
exchangeStrings(array1);
System.out.println(array1[0]);
System.out.println(array1[1]);
...
public void exchangeStrings(String[] array1)
{
String temp;
temp=array1[0];
array1[0]=array1[1];
array1[1]=temp;
}
12. Recall that a superclass reference variable can be used to point to subclass objects. The following
code needs to have one cast in order to compile. Where should the cast be placed in the code?
String str1="hello";
Object obj1=str1;
String str2=obj1;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!