Let's say you have this piece of code in java: Contact is made from name and number, and PhoneBook from an array of Contacts.
//set -> Does this method really copies and creating new memory place or just pointing to the memory?
public void setContact(Contact[] contact)
{
this.contact = contact; // <----this
}
Thanks.
Arrays are objects, and object references are passed by value in Java. So calling this method makes this.contact be a copy of the reference to the contact array passed as argument. No copy of the array elements is made. No copy of the array is made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With