package testing; public class SimpleClone implements Cloneable { int number = 100; int[] intArray = new int[10]; public SimpleClone() { int number = 100; for (int i = 0; i < intArray.length; i++) { intArray[i] = number; number++; } } public static void main(String[] args) { SimpleClone testclone1 = new SimpleClone(); SimpleClone testclone2; try { testclone2 = (SimpleClone) testclone1.clone(); testclone1.intArray[0] = 1200; testclone2.intArray[0] = 1400; testclone1.number = 1200; System.out.print(" testclone1 intArray[0] = " + testclone1.intArray[0]); System.out.print(" testclone1one2 intArray[0] = " + testclone2.intArray[0]); System.out.print(" testclone1 value of number = " + testclone1.number); System.out.print(" testclone2 value of number = " + testclone2.number); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Reveal answer
Fill a bubble to check yourself
Keep practicing — related questions
- public abstract class AbstractTest { public int getNum() { return 45; } public abstract class Bar { public ...
- package loop; public class TestLoop6 { void testFor() { for (int i = 1; i < 10; i++) { System.out.println("...
- public abstract class AbstractTest { public int getNum() { return 45; } public abstract class Bar { public ...
- package loop; public class TestLoop1 { void testFor() { for (int i = 1; i < 3; i++) { System.out.println("i...
- public class test { public static void main(String args[]) { int i=1, j=1; try { i++; j--; if(i == j) i++; ...
- package simplejava; public class TestConstructor1 { int p; TestConstructor1() { System.out.println("I ...
- package exceptions; public class TestException2 { static double testException(int x, int y) { return (x/y);...
- package varargs; public class TestVarargs1 { public static void displayVal(String... str) { for (String str...