Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

image text in transcribed

image text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Name and describe two anxiety disorders.

Answered: 1 week ago

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

What is Entrepreneur?

Answered: 1 week ago

Question

Which period is known as the chalolithic age ?

Answered: 1 week ago

Question

Guidelines for Informative Speeches?

Answered: 1 week ago