58. copy constructor in java

preview_player
Показать описание
pre-requirement-

copy constructor is a constructo which is used to construct an object by copying the stae from another objet of the same class.

java does not provide default copy constructor so we have to write our own copy constructor.

how to write a copy constructor in java:-
declare a constructor which takes object of same type as an input then manually copy each field of object into new instance.
Рекомендации по теме
Комментарии
Автор

This was super helpful awesome tutorial!

rahulmallah
Автор

This copying comes under shallow or deep?

dhananjayg
Автор

How does this work without using keyword this??

bigbussington
Автор

If I change the value of first objects, what will be the new value?

salmasultanasigma
Автор

I thought java didnt have copy constructor

mayankshankar