1. Default parameter values. Use your own words to describe what is…

1. Default parameter values.

  1. Use your own words to describe what is meant by “default parameter values” (or, simply default parameters)?
  2. Use pseudo code write a function definition and two function calls to illustrate the usage of default value (one call uses default value, while the other call doesn’t use default value).
  3. What is/are the advantage(s) of using default value?
  4. Does Java support default parameter value? Why or why not?

2. (6 points) Consider the following program written in C-like syntax:

void swap(int a, int b) { int temp; temp = a; a = b; b = temp;}

void main() {

  int value = 2, list[5] = {10, 12, 14, 16, 18};

  swap(value, list[2]);

  swap(list[0], list[1]);

  value = 3;                                              

  swap(value, list[value]);

  //now, value = ? list = ? 

}

(a) under pass by value, what are all of the values of the variables value and list at the end?

(b) under pass by reference, what are all of the values of value and list at the end?

 

 

3. (4 points) For the following code segment, assume Java’s parameter passing method is used, will the values of first and second be swapped? Why or why not? Explain briefly.

 

public class myInteger {

    public int value;

myInteger (int i) {value = i;}

}

 

 public static void swap (myInteger a, myInteger b) {

            myInteger temp = a;

            a = b;

            b = temp;           

            return;

}

 

    int first = 7, second = 5;

    myInteger one = new myInteger (first);

    myInteger two = new myInteger (second);

   swap(one, two);

first = one.value;

second = two.value;

//will first = 5 and second = 7?

 

 

Please answer all parts of the questions one by one completely.

 

Typed answers only! 

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions