Answers for "how to copy objects in java"

1

how to copy an object in java

Example example = new Example(1, 2, "Example");
Example copiedExample = new Example(example);

class Example {
  	
  	public int a;
  	public int b;
  	public String c;
  	
	// Constructor
    public Example(int a, int b, String s) {
      // ...
    }
  
  	// Copy Constructor
  	public Example(Example example) {
    	this.a = example.a;
      	this.b = example.b;
      	this.s = example.s;
    }
}
Posted by: Guest on October-11-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language