Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
    }
}
 
PREVIOUS NEXT
Tagged: #copy #object #java
ADD COMMENT
Topic
Name
9+1 =