Sessions-7 Call by ValueReference

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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