ITEC 120 LAB 14 Back to Lab index page

Fun with parameter passing

The point of this lab is to experiment with passing parameters and understand exactly how it works.

Download the class files Num.java and Multiplier.java and the driver program lab14.java. Take a look at the code and decide what you think will happen (predict the output). Compile these and run the driver.

The driver program asks the user to enter an integer number and sends that number to the multiply method. The driver prints out the value of number before and after the call to multiply.

1) What is the value of the int number after the call to multiply? WHY?

You will need to overload the multiply method (in the Multiplier class) by writing two more multiply methods -- one for a double parameter, and one for a Num object. The multiply method for the Num object will multiply the instance data of the Num object. Make sure to use printlns within those methods to show the value of the parameter variable before and after the multiply operation. (much like was done in the multiply(int) method.)

2) What is the value of floatnum before and after the call to multiply? WHY?
3) What is the value of numobj before and after the call to multiply? WHY?

4) How can you explain what is going on?

You might need to draw a diagram of the values being passed as paramters..

To be checked off for this lab, you must answer the 4 questions!