Java Reference
In-Depth Information
17. Which of the following statements is true about the following BaseballTeam class?
1. public class BaseballTeam {
2. private String city, mascot;
3. private int numberOfPlayers;
4.
5. public boolean equals(Object obj) {
6. if(!(obj instanceof BaseballTeam)) {
7. return false;
8. }
9. BaseballTeam other = (BaseballTeam) obj;
10. return (city.equals(other.city)
11. && mascot.equals(other.mascot));
12. }
13.
14. public int hashCode() {
15. return numberOfPlayers;
16. }
17. }
A. The class does not compile.
B. The class compiles but contains an improper equals method.
C. The class compiles but contains an improper hashCode method.
D. The class compiles and has proper equals and hashCode methods.
18. What is the output of the following code?
3. int x = 0;
4. String s = null;
5. if(x == s) {
6. System.out.println(“Success”);
7. } else {
8. System.out.println(“Failure”);
9. }
A. Success
B. Failure
C. Line 4 generates a compiler error.
D. Line 5 generates a compiler error.
19. What is the output of the following code?
3. int x1 = 50, x2 = 75;
4. boolean b = x1 >= x2;
5. if(b = true) {
Search WWH ::




Custom Search