exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 17 discussion

Actual exam question from Oracle's 1z0-809
Question #: 17
Topic #: 1
[All 1z0-809 Questions]

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 n1
boolean 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));
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️
Community vote distribution
A (100%)

Comments

Chosen Answer:
This is a voting comment. You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
M_Jawad
Highly Voted 4 years, 7 months ago
the code prints true
upvoted 10 times
...
asdfjhfgjuaDCV
Most Recent 5 months, 4 weeks ago
A is the correct answer
upvoted 1 times
...
steefaand
6 months, 3 weeks ago
Selected Answer: A
A is correct.
upvoted 1 times
...
duydn
11 months, 2 weeks ago
Selected Answer: A
Code compile successfully and override the equals() correct -> TRUE -> A
upvoted 1 times
...
r1muka5
1 year, 6 months ago
Correct answer is A: public class Book { int id; String name; public Book(int id, String name) { this.id = id; this.name = name; } @Override public boolean equals(Object obj) { boolean output = false; Book b = (Book) obj; if (this.name.equals(b.name)) { output = true; } return output; } } public class Main { public static void main(String[] args) { Book b1 = new Book(101, "Java Programing"); Book b2 = new Book(102, "Java Programing"); System.out.println(b1.equals(b2)); } }
upvoted 1 times
...
Svetleto13
3 years, 4 months ago
A,tested
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SC-900
Auckland, 1 minute ago