Quiz Space

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

Question 5: Consider the code given below. What will the output be?

Question 5

+3 marksOne correct option

Consider the code given below.

java
class Date{
int date, month, year;
//Constructor to initialize instance variables
public String toString() {
return "DOB = " + date + "-" + month + "-" + year;
}
}
class Student{
private String name;
private Date dob;
public Student(String name) {
this.name = name;
}
public Student(Student s) {
this.name = s.name;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String toString() {
return "name = " + name+", "+dob;
}
}
public class ConTest {
public static void main(String[] args) {
Student obj1 = new Student("ABC");
obj1.setDob(new Date(1, 6, 1990));
Student obj2 = new Student(obj1);
obj2.setDob(new Date(31, 1, 1992));
System.out.println(obj1);
System.out.println(obj2);
}
}

What will the output be?

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

Correct answer

  • D

Question 5 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. Q6Consider the code given below. What will the output be?
  6. Q7Consider the code given below. Choose the correct option.
  7. Q8Consider the code given below. Choose the correct option.
  8. Q9Consider the code given below. Choose the correct option.
  9. Q10Consider the code given below. Choose the correct option.
  10. Q11Consider the code given below. Choose the correct option to be filled in place of CODE BLOCK so that the output is: Pum…
  11. Q12Which of the following statements is/are correct?
  12. Q13Consider the code given below that checks whether two vehicles are the same. Method equals is overridden to compare two…
  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…