Create a class, CallClass, with two methods to show call by value and call by reference. One method has two parameters that are any primitive types, whereas the other has a parameter that is an object of any class. Create a CallClassTest class that calls the two methods with proper arguments to show call by value and call by reference. Java

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 13RQ
icon
Related questions
Question

Create a class, CallClass, with two methods to show call by value and call by reference.
One method has two parameters that are any primitive types, whereas the other has a
parameter that is an object of any class. Create a CallClassTest class that calls the two
methods with proper arguments to show call by value and call by reference.

Java

Expert Solution
Step 1

Java Code: Java code that has a class which have two methods. One method takes call by value and other method takes an object of class. Screenshot of the code and output has been attached.

import java.io.*;
class CallClass//class CallClass
{
int e,f;//data member of the class
  
   public CallClass()//constructor
   {
   e = 15;//initialization of members
f = 20;
   }
   public void callVal(int a,int b)//method that takes parameters as value
   {
       System.out.println("Call by Value a: "+a);//print values of parameters passing
       System.out.println("Call by Value b: "+b);
   }
   public void callRef(CallClass c)//method takes argument as CallClass object
   {
       System.out.println("Call by Reference a: "+c.e);//by class reference access data members
       System.out.println("Call by Reference b: "+c.f);
   }
}
class Main//test class
{
   public static void main(String[]args)
   {
       CallClass c1 = new CallClass();//creates object of the class
       c1.callVal(5,10);//call by value
       c1.callRef(c1);//call by Reference
   }
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Development strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT