Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

copy constructor in java

public class CopyConstructorExample {
  
	private int someInt;
  	private String someString;
	private Date someDate;
  
  	public CopyConstructorExample(CopyConstructorExample example) {
    	this.someInt = example.getSomeInt();
    	this.someString = example.getSomeString();
      	this.someDate = new Date(example.getSomeDate().getTime()); 
      	// We need to construct a new Date object, else we would have the same date object
    }
  
  // Other Constructors here
  // Getters and Setters here
}
public class UsageExample {
	public static void main(String[] args) {
    	CopyConstructorExample example = new CopyConstructorExample(5, "Test");
      	// Copy example using the Constructor
      	CopyConstructorExample copy = new CopyConstructorExample(example);
      	
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java quick sort 
Java :: how to find numbers of digits in java 
Java :: abstract class in java 
Java :: how to close a jframe in netbeans 
Java :: Array list deep copy 
Java :: random boolean java 
Java :: unique elements in array java 
Java :: fill two dimensional array java 
Java :: string to stream java 
Java :: java string array to one string 
Java :: how to find the length of a string in java without using length function 
Java :: No Java files found that extend CordovaActivity. [ERROR] An error occurred while running subprocess cordova. 
Java :: javac clear 
Java :: java booleans 
Java :: send data from service to activity class 
Java :: java set foreach 
Java :: difference between two LocalDateTime java 
Java :: bean factory vs application context 
Java :: java throw keyword 
Java :: java replace element in list 
Java :: loop hash map 
Java :: heap in java 
Java :: spring boot MVC config 
Java :: sort comparator in java 
Java :: flink prometheus alert on failed jobs 
Java :: add character to a string java 
Java :: nosuchelementexception 
Java :: how to create alert dialog in android studio 
Java :: How to efficiently reverse a singly linked list, in Java? 
Java :: how to use a combo box in java with if else 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =