The constructor which is used to copy one object into another object, is known as copy constructor. Actually it is the constructor in C++, not in java. Since java supports all C++ features, so this concept is supported.
Example3;
package java8s;
class A { int x,y; A(int p, int q) //parameterized constructor { x=p; y=q; } A(A r) // copy constructor { x=r.x; y=r.y; } void show() { System.out.println("x="+x); System.out.println("y="+y); } } class Example1 { public static void main(String[] args) { A ob1=new A(100,200); A ob2=new A(ob1); System.out.println("in ob1"); ob1.show(); System.out.println("in ob2"); ob2.show(); } }
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc