Question: (3) (10 points) This question is about understanding the difference between passing a primitive data value verse an object reference through a method (argument). For

 (3) (10 points) This question is about understanding the difference between

passing a primitive data value verse an object reference through a method

(3) (10 points) This question is about understanding the difference between passing a primitive data value verse an object reference through a method (argument). For the question, you are asked to convert a program that uses the "pass by value" to "pass by reference" as an argument to a given method with an object. You can download the "pass by value" method program (CallValue Test.java) from eLearn assignment3. The program runs "as it": Before calling t.calc(a,b): a = 15 b = 20 inside t.calc(a, b): a = 30 b = 10 exit from t.calc(a,b): a = 15 b = 20 Convert the calculation method (calc(..)) in the CallValue Test class to use "pass by reference" method. You also need to modify the Test Class attributes for this program to support this. Your program should display: Before calling tx.calc(a, b) 15 b = 20 inside tx.calc(a, b): a = 30 b = 10 exit from tx.calc(a, b): a=30 b = 10 class Test { void calc(int x, int y) { x*= 2; y/=2; System.out.println(" inside t.calc(a, b):\ta="+x+"b="+y); public class CallByValue Test { public static void main (String args[]) { Test t= new Test(); int a =15, b= 20; System.out.println ("Before calling t.calc(a,b): a="+a+"b=" + b); t.calc (a, b); System.out.println(" exit from t.calc(a,b):\ta="+a+"b="+b)

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!