Java Pass by Value - Javatpoint
Java Pass by Value - Javatpoint
Write be(er
code
Open
value
reference
result
value-result
name
Sponsored
Sponsored
Bike.java
public class Bike {
private double speed;
public void Model(){}
public Bike(double s){
this.speed=s;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double s1) {
this.speed = speed;
}
}
TestSpeed.java
public class TestSpeed {
public static void main(String[] args) {
Bike apache = new Bike(180); //memory referen
Bike pulsar = new Bike(200);
swap(apache, pulsar);
System.out.println("Apache's Speed is ="+apac
System.out.println("Pulsar's Speed is ="+pulsa
Demo(pulsar);
System.out.println("Pulsar's Speed is ="+pulsa
}
private static void Demo(Bike b) {
b.setSpeed(180);
b = new Bike(280);
b.setSpeed(200);
}
public static void swap(Object o1, Object o2)// m
{
Object temp = o1;
o1=o2;
o2=temp;
}
}
Output:
public static void swap(Object o1, Object o2)
{
Object temp = o1;
o1=o2;
o2=temp;
}
PBVDemo.java
public class PBVDemo {
int a=100;
void change(int a){
a=a+100;//Changing values It will be locally)
}
public static void main(String args[]){
PBVDemo p=new PBVDemo(); //Creating objec
System.out.println(" Value (before change)="+p
p.change(500); //Passing value
System.out.println(" Value (after change)="+p.a
}
}
Output:
← Prev Next →
Youtube
For Videos Join Our Youtube
Channel: Join Now
Feedback
Splunk SPSS
Swagger Transact-SQL
Tumblr ReactJS
Regex tutorial
Regex Reinforcement
Learning
RxJS tutorial
R Programming RxJS
Keras tutorial
Keras
Preparation
Aptitude
Aptitude Reasoning
Verbal Ability
Company
Questions
Trending Technologies
AWS Tutorial
Artificial AWS
Intelligence
Selenium tutorial
Hadoop ReactJS
Git Tutorial
Blockchain Git
DevOps Tutorial
B.Tech / MCA
DBMS tutorial
DAA tutorial
Computer Discrete
Organization Mathematics
html tutorial
Automata Tutorial
C++ tutorial
C Programming C++
Java tutorial
Java .Net
Python Programs
Data Warehouse