ProAnswers.org

How to use class type as method parameters?

The following code passes objects to methods.

 class Test {
  int a;
 
  Test(int i) {
    a = i;
  }
  boolean equals(Test o) {
    if (o.a == a )
      return true;
    else
      return false;
  }
}
 
public class Main {
  public static void main(String args[]) {
    Test ob1 = new Test(100);
    Test ob2 = new Test(100);
 
    System.out.println("ob1 == ob2: " + ob1.equals(ob2));
 
  }
}