SlideShare a Scribd company logo
 Call by value and call by reference
Call by value: this approach copies the value of arguments in to format
parameters of subroutine. Therefore changesmade to the parameter of the
subroutine have no effecton the argument in call.
Example:
Class Test
{
Void noChange(int i,int
j)
{
i=i+j;
j=-j;
}
}
class Callvalue
{
Public static void main(String arr[])
{
Test ob= new Test();
Int a=15,b=20;
System.out.println(“a and b before
claa:”+a+” “+b);
Ob.noChange(a,b)
System.out.println(a and b after
call:”+a+” “+b);
}
}
Output:
A and b before call 15 20
A and b after call 15 20
 Call by Reference:
When we pass object(ob) to a method situation is different. When we create a
variable of class type we create reference.
When we pass an object as an argument in reality we are not passing the
objectitself but only the reference that refer to that object. so object passedto
method is effectively callby reference, changesto objectinside method do
effect.
Class Test
{
Int a,b;
Test(int i,int j)
{
A=I;
B=j;
}
Void change(Test ob)
{
Ob.a=ob.a+ob.b;
Ob.b=-ob.b;
}
}
Class Passobj
{
Public static void main(String arr[])
{
Test ob= new Test(15,20);
System.out.println(“a and b before
call”+ob.a+””+ob.b);
Ob.change(ob);
System.out.println(“a and b after
call”+ob.a+””+ob.b);
}
}
Output:==========================================
a and b before call 15 20
a and b after call 35 -20
 variablelength argument:
Here the parameterlist for a variable argument method is not fixed but
rather variable in length.
The variable length argument is specifiedby three periods(…).
Example :
Class Varargs
{
Static void VaTest(int …v)
{
System.out.println(“number
of args:”+v.length);
For(int i=0;i<v.length;i++)
{
System.out.println(“arg”+i+”:”+v[i
]);
System.out.println();
}
System.out.println(“contents:”
);
Public static void main(String arr[])
{
VaTest(10);
VaTest(1,2,3);
VaTest();
}
}
Output:
No of args:1
Content:
Arg 0:10
No of args:3
Content:
Arg 0:1
Arg1:2
Arg2:3
No of args:0
Content:
Inside VaTest() v is operated on as array. This is because v is an
array. The … simple tells the compiler that a variables no. of
arguments will be used and that these arguments will be stored in
the array referred to by v.
Class Vararg
{
Public static void
main(string arg[])
Static void VaTest(string msg,int …v)
{
System.out.println(msg+v.length);
System.out.println();
For(int i=0;i<v.length;i++)
System.out.println(“arg”+i+”:”+v[i]);
System.out.println();
}
{
VaTest(“one vararg”,10);
VaTest(“three
Vararg:”,1,2,3);
VaTest(“No varargs:”);
}
 Static
1. Static may be a variable.
2. Static may be a method
3. Static may be a block
 Static Block:
Class Staticblock
{
Public static void main(String
arr[])
{
System.out.println(“main
method executed after”);
}
Static
{
System.out.println(“static block
is executed first”);
}
}
Static block can be used to check condition before the execution of
main method. So output of program is
Static block is executed first
Main method executed after
Static methods:
Class Language
{
Public static void
main(String arr[])
{
Display();
}
Static void display()
{
System.out.println(“java is
good I am inside static
method”);
}
}

Static method in java can be called without creating an object of
class.
Class Diff
{
Public static void main(String arr[])
{
Display(); //calling without
object
Diff t= new Diff(); //object ref.
t.show(); // calling using object
}
Static void display()
{
System.out.println(“Program is
Good”);
}
Void show()
{
System.out.println(“java is good
so I am inside method so called
me with object”);
}
}
So instance method require an object of its class to be created before
it can be called while static method does not require object creation.

More Related Content

What's hot

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
Saurav Kumar
 
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180
Mahmoud Samir Fayed
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
AravindSankaran
 
The Ring programming language version 1.5.1 book - Part 30 of 180
The Ring programming language version 1.5.1 book - Part 30 of 180The Ring programming language version 1.5.1 book - Part 30 of 180
The Ring programming language version 1.5.1 book - Part 30 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210
Mahmoud Samir Fayed
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUI
kiahiska
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
Prem Kumar Badri
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
 
C# Loops
C# LoopsC# Loops
C# Loops
guestae0484
 
Templates
TemplatesTemplates
Templates
Farwa Ansari
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
Radim Pavlicek
 
Java8: Language Enhancements
Java8: Language EnhancementsJava8: Language Enhancements
Java8: Language Enhancements
Yuriy Bondaruk
 
CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)
Nada Kamel
 
Loop c++
Loop c++Loop c++
Loop c++
Mood Mood
 
MCRL2
MCRL2MCRL2
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
Rokonuzzaman Rony
 
Concurrency in Programming Languages
Concurrency in Programming LanguagesConcurrency in Programming Languages
Concurrency in Programming Languages
Yudong Li
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Ontico
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
gourav kottawar
 

What's hot (20)

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
The Ring programming language version 1.5.1 book - Part 30 of 180
The Ring programming language version 1.5.1 book - Part 30 of 180The Ring programming language version 1.5.1 book - Part 30 of 180
The Ring programming language version 1.5.1 book - Part 30 of 180
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUI
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Templates
TemplatesTemplates
Templates
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
 
Java8: Language Enhancements
Java8: Language EnhancementsJava8: Language Enhancements
Java8: Language Enhancements
 
CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)
 
Loop c++
Loop c++Loop c++
Loop c++
 
MCRL2
MCRL2MCRL2
MCRL2
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
 
Concurrency in Programming Languages
Concurrency in Programming LanguagesConcurrency in Programming Languages
Concurrency in Programming Languages
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
 

Similar to Call by value and call by reference and varaiable length arguments

Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
sholavanalli
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
Geetha Manohar
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
worldchannel
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
khush_boo31
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
Simon Ritter
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
adityaraj7711
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
GOKULKANNANMMECLECTC
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
manish kumar
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
adityavarte
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Materials for teachers and students java-en
Materials for teachers and students java-enMaterials for teachers and students java-en
Materials for teachers and students java-en
Georgeta Manafu
 
Array Cont
Array ContArray Cont
Java ppt
Java pptJava ppt
Java ppt
Rohan Gajre
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
Hortonworks
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 

Similar to Call by value and call by reference and varaiable length arguments (20)

Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Materials for teachers and students java-en
Materials for teachers and students java-enMaterials for teachers and students java-en
Materials for teachers and students java-en
 
Array Cont
Array ContArray Cont
Array Cont
 
Java ppt
Java pptJava ppt
Java ppt
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 

More from vishal choudhary

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
vishal choudhary
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
vishal choudhary
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
vishal choudhary
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
vishal choudhary
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
vishal choudhary
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
vishal choudhary
 
XML.pptx
XML.pptxXML.pptx
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
vishal choudhary
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
vishal choudhary
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
vishal choudhary
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
vishal choudhary
 
SE1.ppt
SE1.pptSE1.ppt
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
vishal choudhary
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
vishal choudhary
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
vishal choudhary
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
vishal choudhary
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
vishal choudhary
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
vishal choudhary
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
vishal choudhary
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
vishal choudhary
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Recently uploaded

How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 

Recently uploaded (20)

How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 

Call by value and call by reference and varaiable length arguments

  • 1.  Call by value and call by reference Call by value: this approach copies the value of arguments in to format parameters of subroutine. Therefore changesmade to the parameter of the subroutine have no effecton the argument in call. Example: Class Test { Void noChange(int i,int j) { i=i+j; j=-j; } } class Callvalue { Public static void main(String arr[]) { Test ob= new Test(); Int a=15,b=20; System.out.println(“a and b before claa:”+a+” “+b); Ob.noChange(a,b) System.out.println(a and b after call:”+a+” “+b); } } Output: A and b before call 15 20 A and b after call 15 20  Call by Reference: When we pass object(ob) to a method situation is different. When we create a variable of class type we create reference. When we pass an object as an argument in reality we are not passing the objectitself but only the reference that refer to that object. so object passedto method is effectively callby reference, changesto objectinside method do effect.
  • 2. Class Test { Int a,b; Test(int i,int j) { A=I; B=j; } Void change(Test ob) { Ob.a=ob.a+ob.b; Ob.b=-ob.b; } } Class Passobj { Public static void main(String arr[]) { Test ob= new Test(15,20); System.out.println(“a and b before call”+ob.a+””+ob.b); Ob.change(ob); System.out.println(“a and b after call”+ob.a+””+ob.b); } } Output:========================================== a and b before call 15 20 a and b after call 35 -20  variablelength argument: Here the parameterlist for a variable argument method is not fixed but rather variable in length. The variable length argument is specifiedby three periods(…). Example : Class Varargs { Static void VaTest(int …v) { System.out.println(“number of args:”+v.length); For(int i=0;i<v.length;i++) { System.out.println(“arg”+i+”:”+v[i ]); System.out.println(); }
  • 3. System.out.println(“contents:” ); Public static void main(String arr[]) { VaTest(10); VaTest(1,2,3); VaTest(); } } Output: No of args:1 Content: Arg 0:10 No of args:3 Content: Arg 0:1 Arg1:2 Arg2:3 No of args:0 Content: Inside VaTest() v is operated on as array. This is because v is an array. The … simple tells the compiler that a variables no. of arguments will be used and that these arguments will be stored in the array referred to by v. Class Vararg { Public static void main(string arg[])
  • 4. Static void VaTest(string msg,int …v) { System.out.println(msg+v.length); System.out.println(); For(int i=0;i<v.length;i++) System.out.println(“arg”+i+”:”+v[i]); System.out.println(); } { VaTest(“one vararg”,10); VaTest(“three Vararg:”,1,2,3); VaTest(“No varargs:”); }  Static 1. Static may be a variable. 2. Static may be a method 3. Static may be a block  Static Block: Class Staticblock { Public static void main(String arr[]) { System.out.println(“main method executed after”); } Static { System.out.println(“static block is executed first”); } } Static block can be used to check condition before the execution of main method. So output of program is Static block is executed first Main method executed after
  • 5. Static methods: Class Language { Public static void main(String arr[]) { Display(); } Static void display() { System.out.println(“java is good I am inside static method”); } }  Static method in java can be called without creating an object of class. Class Diff { Public static void main(String arr[]) { Display(); //calling without object Diff t= new Diff(); //object ref. t.show(); // calling using object } Static void display() { System.out.println(“Program is Good”); } Void show() { System.out.println(“java is good so I am inside method so called me with object”); } } So instance method require an object of its class to be created before it can be called while static method does not require object creation.