What is the use of the method: public boolean equals(Object otherObject)

currently we are in a lesson about Java Generics.

I am currently working on two (2) examples/java classes given by the prof. We were instructed to test out and study the program and I can’t seem to understand or read the code block below in “simple english”

public boolean equals(Object otherObject) {
    if (otherObject == null) {
        return false;
    } else if (getClass() != otherObject.getClass()) {
        return false;
    } else {
        Pair<T> otherPair = (Pair<T>) otherObject;
        return (first.equals(otherPair.first) && second.equals(otherPair.second));
    }

}

I’ve looked around the internet and found some useful information but I can only tell that the method above is used to check if the field values are the same.

Link where I read about it: https://ecs.wgtn.ac.nz/foswiki/pub/Courses/COMP103_2018T2/Schedule/week4-4up.pdf

The program extracts two inputs of Data Type String , the user must guess the two secret words correctly, in the case of getting the correct answer, the program will let the user know about their answers.

Here’s the two classes (Class Definition With Type Parameter) with the class that has the main method:

GenericPairDemo Class:

import java.util.Scanner;

public class GenericPairDemo {

    public static void main (String []args){

        Pair<String> secretPair = new Pair<>("Happy", "Day");


        Scanner kbd = new Scanner(System.in);


        System.out.println("Enter two words:");
        String word1 = kbd.next();
        String word2 = kbd.next();

        Pair<String> inputPair = new Pair<String>(word1, word2);

        if (inputPair.equals(secretPair)){
            System.out.println("You guessed the secret words");
            System.out.println("in the correct order!");
        } else {

            System.out.println("You guessed incorrectly");
            System.out.println("You guessed: ");
            System.out.println(inputPair);
            System.out.println("The secret words are: ");
            System.out.println(secretPair);

        }

    } // end of main
}

Pair Class:

public class Pair <T> {

    private T first;
    private T second;


    // constructor
    public Pair(T firstItem, T secondItem){
        this.first = firstItem;
        this.second = secondItem;
    }


    // getters and setters
    public T getFirst() {
        return first;
    }

    public T getSecond() {
        return second;
    }

    public void setFirst(T first) {
        this.first = first;
    }

    public void setSecond(T second) {
        this.second = second;
    }

    // printing
    public String toString(){
        return ("First: " + first.toString() + "n" + "Second: " + second.toString());
    }


    public boolean equals(Object otherObject) {
        if (otherObject == null) {
            return false;
        } else if (getClass() != otherObject.getClass()) {
            return false;
        } else {
            Pair<T> otherPair = (Pair<T>) otherObject;
            return (first.equals(otherPair.first) && second.equals(otherPair.second));
        }

    }


}

Would also appreciate if someone could explain how the else statement works:

} else {
            Pair<T> otherPair = (Pair<T>) otherObject;
            return (first.equals(otherPair.first) && second.equals(otherPair.second));
        }