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.contactbe 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.