VIPS OOPS Unit 2 Constructor
VIPS OOPS Unit 2 Constructor
id = i; name = n; } s1.display();
void display(){System.out.println(id+" } }
"+name);} Output:
public static void main(String args[]){ 101 Pooja
201 Shivam
Java Copy Constructor
There is no copy constructor in Java. However, • Unlike other constructors copy
we can copy the values from one object to constructor is passed with another
another like copy constructor in C++. object which copies the data
available from the passed object to
the newly created object.
• There are many ways to copy the values of
one object into another in Java. They are:
• Note: In Java,there is no such inbuilt
copy constructor available like in
• By constructor other programming languages such
as C++, instead we can create our
• By assigning the values of one object into own copy constructor by passing the
another object of the same class to the other
• By clone() method of Object class instance(object) of the class.
//Java program to initialize the values from
one object to another object.