0% found this document useful (0 votes)
34 views9 pages

Sessions-7 Call by ValueReference

This document discusses call by value and call by reference in Java. It provides examples of passing primitive data types by value and object references by reference. It also lists some example programs, including calculating factorials and bubble sorting arrays, and demonstrates how to pass an object to a method by reference using a Box class. The document suggests discussing call by reference further in another session.

Uploaded by

priya uppala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views9 pages

Sessions-7 Call by ValueReference

This document discusses call by value and call by reference in Java. It provides examples of passing primitive data types by value and object references by reference. It also lists some example programs, including calculating factorials and bubble sorting arrays, and demonstrates how to pass an object to a method by reference using a Box class. The document suggests discussing call by reference further in another session.

Uploaded by

priya uppala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

SESSION 5

sessions-7
Call Class
by value,and
call by reference
Object
Introduction to call by value

It is used to pass the data from one function to another

SESSION
All data types can be passed 5
Array can also be passed
Class and Object
An object of a class can also be passed (call by reference)

This can be discussed in another session


call by value conti…

1. Calling statement
SESSION 5
2. Called function

3. Return types
Class and Object
4. Parameters
A) actual parameters
B) formal parameters
model programs

1. Write a factorial program which has a method to take a


integer number, and return the factorial of that number
SESSION 5
2. Write a bubble sort program which has a method to accepts
an integer array and returns the sorted array.
Class and Object
Exercise problems of your choice

SESSION 5

Class and Object


call by reference

What is a reference
SESSION 5
Eg: Box b1=new Box(10,20,30);

Box b2;
Class and Object
b2=b1

This means,
All the data and methods of b1 are now shared with b2
Let us see call by reference
This is similar to call by value, in the place of
ordinary variable we use object reference.
SESSION 5
Eg. Box b1= new Box(10,20,30)

Class
Calling statement: andb1)
volume( Object
Called method:
Void volume( Box b2){
System.out.println( b2.w*b2.h*.b2.);
}
Exercise programs

1. Write a java program to demonstrate call by


reference (Box9.java
SESSION, Box9Demo.java)
5

Class and Object


SESSION 5
end of sessions
Class and Object

You might also like