Quiz Space

Programming Concepts using Java · Quiz 1 · 23 Feb 2025 · January 2025 term

Question 6: Consider the code given below that checks whether two pla…

Question 6

+7 marksOne correct option

Consider the code given below that checks whether two players are the same. Method equals is overridden to compare two Player objects as follows.
If two players have the same playerID and teamName, then they are said to be equal.

java
class Player {
private String playerID;
private String teamName;
// Constructor to initialize instance variables
public boolean equals(Object obj) {
//CODE BLOCK
}
}
public class Test {
public static void main(String[] args) {
Player p1 = new Player("004", "Red");
Player p2 = new Car("004", "Red");
if (p1.equals(p2))
System.out.println("p1 and p2 are same");
else
System.out.println("p1 and p2 are different");
}
}

Choose the correct option to fill in place of CODE BLOCK so that the output is:
p1 and p2 are same

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 6 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 23 Feb 2025, in the January 2025 term (IIT M DIPLOMA AN EXAM QDD2 23 Feb 2025). It carries 7 marks.

More questions from this paper

  1. Q1Consider the code given below. How many activation records are created while executing this code?
  2. Q2Figure question
  3. Q3Consider the Java code given below. What will the output be?
  4. Q4Consider the code given below. Choose the correct option.
  5. Q5Consider the Java code given below. Choose the correct option.
  6. Q7Consider the Java code given below. Choose the correct option.
  7. Q8Consider the Java code given below. What will the output be?
  8. Q9Consider the Java code given below. Choose the correct option.
  9. Q10Consider the Java code given below. Which of the following statements is FALSE?
  10. Q11Consider the Java code given below. Identify the correct option to fill in place of CODE BLOCK, such that the output is…
  11. Q12Consider the Java code given below. Choose the correct option.
  12. Q13Consider the code given below.
  13. Q14Consider the Java program below. Identify the correct option(s) to fill in the blank at LINE 1, such that the output is…
  14. Q15Consider the Java code given below. Identify the correct option(s) to fill in the blank at LINE 1, such that the output…