Quiz Space

Programming Concepts using Java · Quiz 2 · 1 Dec 2024 · September 2024 term

Question 14: Consider the following Java code. What will the output b…

Question 14

+7 marksOne correct option

Consider the following Java code.

java
class Task implements Cloneable {
String taskName;
public Task(String n) {
taskName = n;
}
public Task clone() throws CloneNotSupportedException {
return (Task) super.clone();
}
}
class Project implements Cloneable {
String projectName;
Task task1;
Task task2;
public Project(String pN, Task t1, Task t2) {
projectName = pN;
task1 = t1;
task2 = t2;
}
public Project clone() throws CloneNotSupportedException {
Project p = (Project) super.clone();
p.task1 = p.task1.clone();
p.task2 = p.task2.clone();
return p;
}
}
public class Test {
public static void main(String[] args) throws CloneNotSupportedException {
Task t1 = new Task("Design");
Task t2 = new Task("Development");
Project proj1 = new Project("ProjectX", t1, t2);
Project proj2 = proj1.clone();
proj2.task1.taskName = "Research";
proj2.projectName = "ProjectY";
System.out.println(proj1.projectName + " : " + proj1.task1.taskName);
System.out.println(proj2.projectName + " : " + proj2.task1.taskName);
}
}

What will the output be?

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

Correct answer

  • C

Question 14 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 1 Dec 2024, in the September 2024 term (IIT M DIPLOMA AN EXAM QDD2 01 Dec 2024). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below that prints the price of laptops. From among the options, identify the appropriate f…
  2. Q2Consider the Java code given below. Choose the correct option.
  3. Q3The following code maps a set of athletes names to the number of medals they have won and categorizes the athletes base…
  4. Q4Consider the Java code given below. What will the output be?
  5. Q5Consider the Java code given below that prints the highest purchased amount among a set of given Buyer objects. From am…
  6. Q6Consider the Java code given below. Choose the correct option.
  7. Q7Consider two Java files located in the same package as shown below. A.java: B.java Choose the correct option.
  8. Q8Consider the Java code given below. Identify the first assert statement that throws the AssertionError when the class i…
  9. Q9Consider the Java code given below. Identify the appropriate option to fill in place of LINE 1 such that the output is:
  10. Q10Consider the Java code given below. Choose the correct option to be filled in place of LINE 1 so that the output is:
  11. Q11Consider the Java code given below. What will the output be?
  12. Q12Consider the Java code given below. Choose the correct option to fill in the CODE BLOCK to add the name and average exp…
  13. Q13Consider the Java code given below. Choose the correct option.
  14. Q15Consider the Java code given below that should print the names of vehicles whose mileage is between 15.0 and 25.0 (both…