25. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class C { int i; } class Manager3 { public static void main (String[] args) { C c1 = new C(); C c2 = c1; System.out.println(c1); System.out.println(c2); System.out.println(c1.equals(c2)); System.out.println(c1.hashCode()); System.out.println(c2.hashCode()); } }
26. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class D { int i; // overrided hashCode method from object class public int hashCode() { return i; } } class Manager4 { public static void main (String[] args) { D d1 = new D(); d1.i = 100; D d2 = new D(); d2.i = 200; System.out.println(d1.hashCode()); System.out.println(d2.hashCode()); } }
27. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class E { int i = 10, j = 20; // overrided hashCode method from object class public int hashCode() { return i + j; } E() { } E(int i) { this.i = i; } } class Manager5 { public static void main (String[] args) { E e1 = new E(); E e2 = new E(100); System.out.println(e1.hashCode()); System.out.println(e2.hashCode()); } }
28. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class F { F obj; } class Manager6 { public static void main(String[] args) { F f2 = new F(); F f3 = new F(); F f4 = new F(); f2.obj = f3; f3.obj = f4; f4.obj = f2; f2 = f3 = f4 = null; System.out.println("done"); } }
29. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
// finalize method used here class G { protected void finalize() throws Throwable { System.out.println("Finalize"); } } class Manager7 { public static void main(String[] args) { G g1 = new G(); g1 = null; System.gc(); System.out.println("done"); } }
30. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
//cloneUsage method used here class H implements Cloneable { int i; void cloneUsage() { try { H h1 = (H) clone(); System.out.println(h1.i); } catch(CloneNotSupportedException ex) { ex.printStackTrace(); } } } class Manager8 { public static void main(String[] args) { H obj = new H(); obj.i = 300; obj.cloneUsage(); } }