SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
CALL BY VALUE AND
CALL BY REFERENCE
IN JAVA
PROF. SUNIL D. CHUTE
DEPT. OF COMPUTER SCIENCE
MG COLLEGE ARMORI
• There is only call by value in java, not call by
reference. If we call a method passing a value, it is
known as call by value. The changes being done in
the called method, is not affected in the calling
method.
EXAMPLE OF CALL BY VALUE IN JAVA
class Operation{
int data=50;
void change(int data)
{
data=data+100;
}
public static void main(String args[]){
Operation op=new Operation();
System.out.println("before change "+op.data);
op.change(500);
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 50
ANOTHER EXAMPLE OF CALL BY VALUE IN JAVA
• In case of call by reference original value is
changed if we made changes in the called method.
If we pass object in place of any primitive value,
original value will be changed. In this example we
are passing object as a value. Let's take a simple
example:
class Operation2
{
int data=50;
void change(Operation2 op)
{
op.data=op.data+100;//changes will be in the instan
ce variable
}
public static void main(String args[])
{
Operation2 op=new Operation2();
System.out.println("before change "+op.data);
op.change(op);//passing object
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 150

More Related Content

PPTX
Arrays In C++
PPTX
Asymptotic notations
PPTX
Arrays in Java
PPTX
Constructor in java
PPT
Data Structures- Part5 recursion
PPTX
Characteristics of OOPS
PPTX
Prefix, Infix and Post-fix Notations
PDF
Method Overloading In Java
Arrays In C++
Asymptotic notations
Arrays in Java
Constructor in java
Data Structures- Part5 recursion
Characteristics of OOPS
Prefix, Infix and Post-fix Notations
Method Overloading In Java

What's hot (20)

PPT
Difference between stack and queue
PPTX
Data types in C
PPTX
Presentation on array
PPTX
Priority Queue in Data Structure
PPT
PPT
Array in c
PPTX
Java packages
PPTX
Operators in java
PDF
Operators in c programming
PPTX
PPTX
Function in C program
PDF
Triggers in SQL | Edureka
PPTX
PPTX
Selection sorting
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPTX
Breadth First Search & Depth First Search
PDF
PL/SQL TRIGGERS
PPTX
Function in C Programming
PPTX
Inheritance in java
Difference between stack and queue
Data types in C
Presentation on array
Priority Queue in Data Structure
Array in c
Java packages
Operators in java
Operators in c programming
Function in C program
Triggers in SQL | Edureka
Selection sorting
C lecture 4 nested loops and jumping statements slideshare
Breadth First Search & Depth First Search
PL/SQL TRIGGERS
Function in C Programming
Inheritance in java
Ad

Similar to Call by value and call by reference in java (20)

PPTX
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
PPTX
call by value.pptxGE3791 - Human Values and Ethics
PPTX
call by value.pptxGE3791 - Human Values and Ethics
PPTX
Functions1
PPTX
Lecture 4_Java Method-constructor_imp_keywords
PPTX
Introduction to java programming
PPTX
3 Function & Storage Class.pptx
PDF
Lec21-CS110 Computational Engineering
PPTX
Java basics-includes java classes, methods ,OOPs concepts
PPTX
Method overloading
PPTX
Method overloading
PPTX
L03 Software Design
PDF
C Language Lecture 15
PPTX
Pi j1.3 operators
PPTX
Object Oriented Programming using C++ Unit 1
DOCX
Methods in Java
PDF
03 function overloading
PPTX
Functions in php
DOCX
Call by value and call by reference and varaiable length arguments
PDF
Method overloading, recursion, passing and returning objects from method, new...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
call by value.pptxGE3791 - Human Values and Ethics
call by value.pptxGE3791 - Human Values and Ethics
Functions1
Lecture 4_Java Method-constructor_imp_keywords
Introduction to java programming
3 Function & Storage Class.pptx
Lec21-CS110 Computational Engineering
Java basics-includes java classes, methods ,OOPs concepts
Method overloading
Method overloading
L03 Software Design
C Language Lecture 15
Pi j1.3 operators
Object Oriented Programming using C++ Unit 1
Methods in Java
03 function overloading
Functions in php
Call by value and call by reference and varaiable length arguments
Method overloading, recursion, passing and returning objects from method, new...
Ad

More from sunilchute1 (10)

PPTX
Programming construction tools
PPTX
Introduction to data structure
PPTX
Sorting method data structure
PPTX
Introduction to data structure
PPTX
Input output statement
PPTX
Basic data types in python
PPTX
Java method
PPTX
Constructors in java
PPTX
C loops
PPT
Basic of c language
Programming construction tools
Introduction to data structure
Sorting method data structure
Introduction to data structure
Input output statement
Basic data types in python
Java method
Constructors in java
C loops
Basic of c language

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
Cell Types and Its function , kingdom of life
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Classroom Observation Tools for Teachers
Cell Types and Its function , kingdom of life
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
VCE English Exam - Section C Student Revision Booklet
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A systematic review of self-coping strategies used by university students to ...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...

Call by value and call by reference in java

  • 1. CALL BY VALUE AND CALL BY REFERENCE IN JAVA PROF. SUNIL D. CHUTE DEPT. OF COMPUTER SCIENCE MG COLLEGE ARMORI
  • 2. • There is only call by value in java, not call by reference. If we call a method passing a value, it is known as call by value. The changes being done in the called method, is not affected in the calling method.
  • 3. EXAMPLE OF CALL BY VALUE IN JAVA class Operation{ int data=50; void change(int data) { data=data+100; } public static void main(String args[]){ Operation op=new Operation(); System.out.println("before change "+op.data); op.change(500); System.out.println("after change "+op.data); } } Output:before change 50 after change 50
  • 4. ANOTHER EXAMPLE OF CALL BY VALUE IN JAVA • In case of call by reference original value is changed if we made changes in the called method. If we pass object in place of any primitive value, original value will be changed. In this example we are passing object as a value. Let's take a simple example:
  • 5. class Operation2 { int data=50; void change(Operation2 op) { op.data=op.data+100;//changes will be in the instan ce variable } public static void main(String args[]) { Operation2 op=new Operation2(); System.out.println("before change "+op.data); op.change(op);//passing object System.out.println("after change "+op.data); } } Output:before change 50 after change 150