Quiz Space

Programming Concepts using Java · Quiz 2 · 4 Aug 2024 · May 2024 term

Question 14: Consider the Java code given below. Identify the appropr…

Question 14

+8 marksOne or more correct options

Consider the Java code given below.

java
interface Element {
void display();
}
class PeriodicTableElement {
private String group;
public void setGroup(String g) {
this.group = g;
}
public String getGroup() {
return group;
}
public Element createElement() {
switch (getGroup()) {
case "Metal":
return new Metal();
case "Nonmetal":
return new Nonmetal();
case "Metalloid":
return new Metalloid();
default:
return null;
}
}
private class Metal implements Element {
public void display() {
System.out.println("Metal properties");
}
}
private class Nonmetal implements Element {
public void display() {
System.out.println("Nonmetal properties");
}
}
private class Metalloid implements Element {
public void display() {
System.out.println("Metalloid behavior");
}
}
}
public class ChemistryLab {
public static void main(String[] args) {
PeriodicTableElement pt = new PeriodicTableElement();
pt.setGroup("Metalloid");
// --------- Line X ---------
}
}

Identify the appropriate option to fill in place of LINE X such that the output is:
Metalloid behavior

Select all that apply.

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

Correct answers

  • A
  • C

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

More questions from this paper

  1. Q1Consider the Java code given below. The method boolean containsKey (Object key) in the class Map returns true if and on…
  2. Q2Consider two Java files located in two different packages as shown below. Vehicle.java: Car.java Choose the correct opt…
  3. Q3Consider the Java code given below. Choose the correct option when the program is executed as:\ java -ea Test
  4. Q4Consider the Java code given below. Choose the correct option.
  5. Q5Consider the Java code given below. Choose the correct option(s) to fill in place of CODE BLOCK so that the output is:\…
  6. Q6Consider the Java code given below. What will the output be?
  7. Q7Consider the Java code given below. What will the output be?
  8. Q8Consider the Java code given below. Identify the appropriate option to fill in place of LINE X such that the output is:…
  9. Q9Consider the Java code given below. After type erasure, which of the following correctly represents the ArrayOperations…
  10. Q10Consider the Java code given below. Choose the correct option.
  11. Q11Consider the Java code given below. Choose the correct option to be filled in place of LINE 1 so that the output is:\ […
  12. Q12From among the options, choose the code segment that gives the same output as is given by the Java code inside the CODE…
  13. Q13Consider the Java code given below. What will the output be?
  14. Q15Consider the Java code given below that prints the most impressive act among a set of given Performer objects. From amo…