Which statement is true?

Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, “Java Programing”);
Book b2 = new Book (102, “Java Programing”);
System.out.println (b1.equals(b2)); //line n2
Which statement is true?

Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, “Java Programing”);
Book b2 = new Book (102, “Java Programing”);
System.out.println (b1.equals(b2)); //line n2
Which statement is true?

A.
The program prints true.

B.
The program prints false.

C.
A compilation error occurs. To ensure successful compilation, replace line n1 with:
boolean equals (Book obj) {

D.
A compilation error occurs. To ensure successful compilation, replace line n2 with:
System.out.println (b1.equals((Object) b2));



Leave a Reply 7

Your email address will not be published. Required fields are marked *


smh

smh

A or C
both print true.

DG

DG

Not C, because C also states that are a compilation error occurs, which is incorrect.
A

smh

smh

A correct answer.

smh

smh

A is correct. please ignore C.

Berti John

Berti John

A. is correct