Java is Pass by Value and Not Pass by Reference

  • Pass by Value: The method parameter values are copied to another variable and then the copied object is passed, that’s why it’s called pass by value.
  • Pass by Reference: An alias or reference to the actual parameter is passed to the method, that’s why it’s called pass by reference.
public class Main { 
public static void main(String[] args) { 
int x = 5; 
change(x); 
System.out.println(x); 
public static void change(int x)  
x = 10; 
Output:
5

Comments

Popular posts from this blog

SQL basic interview question

gsutil Vs Storage Transfer Service Vs Transfer Appliance