-3
public boolean equals (Object obj){
if (this == obj){
    return true;
}else{
    if(obj instanceof Book) {
        Book book = (Book) obj;

        if(name.equals(book.getName())&& author.equals(book.getAuthor())) {
            return true;
        }
    }
    return false;
}

What does Book book = (Book) obj; mean? Is it different from new?

jhamon
  • 3,603
  • 4
  • 26
  • 37
kaoru
  • 7
  • 1
  • 11
    Does this answer your question? [Casting variables in Java](https://stackoverflow.com/questions/5289393/casting-variables-in-java) – akuzminykh Jul 06 '20 at 08:47

1 Answers1

0

What this means is that you are casting the value of your obj into the new variable that you created called "book", so the book variable will have the same value as the obj variable, but be careful, the values must be the same type.

Cardstdani
  • 4,999
  • 3
  • 12
  • 31