17. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class S { double i; S(double i) { this.i = i; } } class Manager19 { public static void main (String[] args) { S s1 = new S(10.5); S s2 = new S(10.5); S s3 = s2; System.out.println(s1 == s2); System.out.println(s2 == s3); System.out.println(s3 == s1); System.out.println(s1.i == s2.i); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); System.out.println(s3.equals(s1)); } }
18. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class T { int i ; T(int i) { this.i = i; } public boolean equals(Object obj ) { T t1 = (T)obj; return i == t1.i; // this.i compiler do it. } } class Manager20 { public static void main (String[] args) { T t1 = new T(89); T t2 = new T(89); System.out.println(t1.equals(t2)); } }
19. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class U { double i ; U(double i) { this.i = i; } public boolean equals(Object obj ) { boolean b = ((U)obj).i == this.i; return b; } } class Manager21 { public static void main (String[] args) { U u1 = new U(80.99); U u2 = new U(80.99); System.out.println(u1.equals(u2)); } }
20. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class V { int i , j; V(int i, int j) { this.i = i; this.j = j; } public boolean equals(Object obj ) { V v1 = (V) obj; boolean b = (i == v1.i && j == v1.j); // this.i and this.j return b; } } class Manager22 { public static void main (String[] args) { V v1 = new V(100, 200); V v2 = new V(100, 200); System.out.println(v1.equals(v2)); } }