Grokking Java Interview Questions
0% completed
Pass by Value in Java
Two methods receive the same shopping cart. The method addMango calls list.add("mango") on it, and afterward the caller sees a cart with one more product. The method empty contains the statement list = new ArrayList<>(), and afterward the caller still sees every product. One method changed the cart and the other did not, although both received it in the same way.
One rule explains both results, and it has no exceptions
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%