Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 18th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. public class Test {
  2.    
  3.     public void test() throws CloneNotSupportedException {
  4.         T t = new T();
  5.         t.setI(10);
  6.         t.setJ(20);
  7.        
  8.         T cloned = (T)t.clone();
  9.         System.out.println(cloned.getI());
  10.         System.out.println(cloned.getJ());
  11.     }
  12.    
  13.    
  14.     public static void main(String[] args) throws CloneNotSupportedException {
  15.         new Test().test();
  16.     }
  17.    
  18.     class T implements Cloneable {
  19.        
  20.         private int i = 0;
  21.         private int j = 0;
  22.        
  23.         public int getI() {
  24.             return i;
  25.         }
  26.  
  27.         public void setI(int i) {
  28.             this.i = i;
  29.         }
  30.  
  31.         public int getJ() {
  32.             return j;
  33.         }
  34.  
  35.         public void setJ(int j) {
  36.             this.j = j;
  37.         }
  38.  
  39.         @Override
  40.         public Object clone() throws CloneNotSupportedException {
  41.             super.clone();
  42.             T clone = new T();
  43.             clone.setI(getI());
  44.             clone.setJ(getJ());
  45.             return clone;
  46.         }
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top