Here is a Java Program to Demonstrate that Objects may be passed to methods.
Here is a Java Program to Execute Above Java Class
Output of Above Java Program
ob1 == ob2: true
ob1 == ob3: false
class Test { int a, b; Test(int i, int j) { a = i; b = j; } // return true if o is equal to the invoking object boolean equals(Test o) { if(o.a == a && o.b == b) return true; else return false; } }
Here is a Java Program to Execute Above Java Class
class PassOb { public static void main(String args[]) { Test ob1 = new Test(100, 22); Test ob2 = new Test(100, 22); Test ob3 = new Test(-1, -1); System.out.println("ob1 == ob2: " + ob1.equals(ob2)); System.out.println("ob1 == ob3: " + ob1.equals(ob3)); } }
Output of Above Java Program
ob1 == ob2: true
ob1 == ob3: false