Quiz Space

Programming Concepts using Java · Quiz 1 · 26 Feb 2023 · January 2023 term

Question 13: Consider the code given below that checks whether two ve…

Question 13

+3 marksOne or more correct options

Consider the code given below that checks whether two vehicles are the same. Method equals is overridden to compare two Vehicle objects as follows. If two vehicles have the same registration number, then they are the same. Based on the given information, answer the question that follows.

java
class Vehicle{
private String regno;
//Constructor to initialize instance variables
public String toString() {
return regno;
}
public boolean equals(Object obj) {
// CODE BLOCK
}
}
public class Test {
public static void main(String[] args) {
Vehicle v1 = new Vehicle("RC12345");
Vehicle v2 = new Vehicle("RC99999");
Vehicle v3 = new Vehicle("RC99999");
if(v1.equals(v3))
System.out.println(v1+", "+v3+" are same");
if(v2.equals(v3))
System.out.println(v2+", "+v3+" are same");
}
}

Choose the correct option(s) to fill in place of CODE BLOCK so that the output is:

RC99999, RC99999 are same

Select all that apply.

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

Correct answer

  • D

Question 13 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 26 Feb 2023, in the January 2023 term (IIT M DIPLOMA AN2 EXAM QPD2 26 Feb 2023). It carries 3 marks.

More questions from this paper

  1. Q1Match the following terms with their descriptions.
  2. Q2Consider the code given below. Choose the correct option.
  3. Q3Consider the code given below. Choose the correct option regarding the given code.
  4. Q4Consider the code given below. Choose the correct option regarding the given code.
  5. Q5Consider the code given below. What will the output be?
  6. Q6Consider the code given below. What will the output be?
  7. Q7Consider the code given below. Choose the correct option.
  8. Q8Consider the code given below. Choose the correct option.
  9. Q9Consider the code given below. Choose the correct option.
  10. Q10Consider the code given below. Choose the correct option.
  11. Q11Consider the code given below. Choose the correct option to be filled in place of CODE BLOCK so that the output is: Pum…
  12. Q12Which of the following statements is/are correct?
  13. Q14Consider the code given below. Choose the correct option(s) that can be filled in place of LINE 1 such that it does not…
  14. Q15Consider the code given below. Choose the correct option(s) to fill in place of CODE BLOCK so that the output is: XYZ J…