Copy constructors have a lot of problems, and in general, cloning is preferable, but if you do want to use a copy constructor here is how:
public University( University univ ){
University univ_copy = new University();
univ_copy.name = univ.getname();
univ_copy.numOfPublications = univ.getnumOfPublications();
univ_copy.departments = new Department[univ.numOfDepartments];
System.arrayCopy( univ.departments, 0, univ_copy.departments, 0, univ.departments.length );
return univ_copy;
}
You can also copy the departments one by one, as opposed to copying them in one step with array copy. The key thing is that you need to allocate a new array for the copy, not re-use the existing array from univ
because then you would not have a copy of the array, just a pointer to the original array.