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
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
![](/static/compass_v2/shared-icons/check-mark.png)
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
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)