Quiz Space

Programming Concepts using Java · Quiz 1 · 7 Jul 2024 · May 2024 term

Question 8: Consider the code given below that checks whether two pho…

Question 8

+7 marksOne correct option

Consider the code given below that checks whether two phones are the same. Method equals is overridden to compare two Phone objects as follows.

If two phones have the same brand and imeiNumber, then they are the same.

java
class Phone {
private String brand;
private int imeiNumber;
// Constructor to initialize instance variables
public boolean equals(Object obj) {
//CODE BLOCK
}
}
public class Test {
public static void main(String[] args) {
Phone p1 = new Phone("Samsung", 123456);
Phone p2 = new Phone("Samsung", 123456);
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(s) 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

  • D

Question 8 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 7 Jul 2024, in the May 2024 term (IIT M DIPLOMA AN EXAM QDD2 7 July 2024). It carries 7 marks.

More questions from this paper

  1. Q1Which of the following statements is/are correct about activation records?
  2. Q2Match the following terms with their descriptions/properties.
  3. Q3Consider the Java code given below. What will the output be?
  4. Q4Consider the Java code given below. Choose the correct option.
  5. Q5Consider the Java code given below. Choose the correct option.
  6. Q6Consider the Java code given below. Choose the correct option to fill in the CODE SEGMENT so that the output is:\ Parro…
  7. Q7Consider the Java code given below. Identify the correct statement to fill in the blank at LINE 1, such that the output…
  8. Q9Consider the Java code given below. What will the output be?
  9. Q10Consider the Java code given below.
  10. Q11Consider the Java code given below. Choose the correct option regarding the above code.
  11. Q12Consider the Java code given below. Choose the correct option.
  12. Q13Consider the Java code given below. Choose the correct option to fill in place of CODE BLOCK to instantiate instance va…
  13. Q14Consider the Java code given below. Identify the appropriate statement to fill in the blank at LINE 1, such that the ou…
  14. Q15Consider the Java code given below. Which of the following statements is FALSE?