Quiz Space

Programming Concepts using Java · End Term · 3 Sept 2023 · May 2023 term · Set QPD1-S1

Question 9: Consider the code given below. Choose the correct option.

Question 9

+4 marksOne correct option

Consider the code given below.

java
import java.util.*;
class Cricketer{
Map<String, String> players = new HashMap<String, String>();
public Cricketer() {
players.put("Rohit", "India");
players.put("Ali", "England");
}
public String getCountry(String t){
return players.get(t);
}
}
public class OptionalTest {
public static void main(String[] args){
Optional<String> op1 = Optional.ofNullable(new Cricketer()
.getCountry("Rohit"));
Optional<String> op2 = Optional.ofNullable(new Cricketer()
.getCountry("ali"));
op1.ifPresent(n->System.out.println(n.toUpperCase()));
op2.ifPresent(n->System.out.println(n.toUpperCase()));
}
}

Choose the correct option.

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

Correct answer

  • B

Question 9 of 23 in the IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 3 Sept 2023, in the May 2023 term (IIT M DIPLOMA ET1 EXAM QPD1 S2 03 Sep). It carries 4 marks.

More questions from this paper

  1. Q1Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a functi…
  2. Q2Consider the following java code What will the output be?
  3. Q3Consider the java code given below What will the output be?
  4. Q4Figure question
  5. Q5Consider the Java code given below.\ You may make use of the method description given below.\ getOrDefault(Object key, …
  6. Q6Consider the Java code given below Choose the correct option(s) to be filled in place of CODE BLOCK so that the program…
  7. Q7Consider the following java code What will the output be?
  8. Q8Consider the following java code Identify the first assert statement that throws the AssertionError when the class is e…
  9. Q10Consider the Java code given below Choose the correct option to be filled in place of CODE BLOCK so that the program ge…
  10. Q11Consider the code given below.\ Assume that, before execution of the given code, the files "file1.txt" and "file2.txt" …
  11. Q12Consider the code given below. What will the output be?
  12. Q13Consider the code given below. What will the output be?
  13. Q14Consider the Java code given below Choose the correct option(s) to be filled in place of LINE 1 so that the program gen…
  14. Q15Consider the three Java files given below.\ Pack1Test.java: Pack2Test.java: Test.java: Choose the correct option.
  15. Q16ConcurrentHashMap is a hash table implementation that supports full concurrency of retrievals and high expected concurr…
  16. Q17Consider the Java program given below and select the correct option from among the given choices.
  17. Q18Consider the Java program given below. Initial state: window with Submit and Cancel buttons, empty label.\ On clicking …
  18. Q19Consider the following code Which of the following is/are possible output(s)?
  19. Q20Consider the code given below. Choose the correct option(s) to be filled in place of CODE BLOCK so that the output is: …
  20. Q21Consider the Java code given below. Choose the correct option.
  21. Q22Consider the code given below. What will the output be?
  22. Q23Consider the following java code: Identify the line/s which has/have error.