ITEC 120 LAB 14 Back to Lab index page

Fun with parameter passing

Download the class files Num.java and Multiplier.java and the driver program lab14.java. 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. What is the value of the int number after the call to multiply?

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.)

What is the value of floatnum before and after the call to multiply?
What is the value of numobj before and after the call to multiply?

How can you explain what is going on?

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

Once you have your program working, show your lab to the Peer Instructor to be checked off. Explain what you think is happening with the values of the parameters being passed.