Quiz Space

Java End Term: 11 December 2022, Set ETD1-2 (September 2022 term)

Question 1

+4 marksOne correct option

ConcurrentHashMap is a hash table implementation that supports full concurrency of retrievals and high expected concurrency for updates. All operations on this collection are thread-safe. Consider the code given below that uses a ConcurrentHashMap, and answer the question that follows.

java
class Example extends Thread{
Map siMap;
//Constructor is defined here
public void run(){
siMap.put("D",4);
}
}
public class FClass{
public static void main (String[] args) {
Map<String, Integer> siMap = new ConcurrentHashMap<String, Integer>();
String[] str = {"A", "B", "C"};
Integer[] arr = {1, 2, 3};
for(int i = 0; i < str.length; i++){
siMap.put(str[i],arr[i]);
}
Example t = new Example(siMap);
t.start();
Set s = siMap.entrySet();
Iterator itr = s.iterator();
while(itr.hasNext()){
Map.Entry m = (Map.Entry)itr.next();
System.out.println(m.getKey() + " => " + m.getValue());
}
}
}

Which of the following is NOT true about the given code?

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

Question 2

+4 marksOne correct option

Consider the code given below.

java
interface Callable{
void call();
}
abstract class SmartPhone implements Callable{ //Line 1
public abstract void record();
}
class Vivo extends SmartPhone{
public void call() {
System.out.println("Vivo call");
}
public void record() {
System.out.println("Vivo record");
}
}
class IPhone extends SmartPhone{
public void call() {
System.out.println("Iphone call");
}
public void record() {
System.out.println("Iphone record");
}
}
public class User {
public static void showDetails(SmartPhone obj) { //Line 2
obj.call();
obj.record();
}
public static void main(String[] args) {
showDetails(new Vivo());
showDetails(new IPhone());
}
}

Choose the correct option regarding the code.

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

Question 3

+4 marksOne correct option

Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a function f to an initial element e, producing a Stream consisting of e, f(e), f(f(e)), etc. Based on the above information, consider the code given below, and answer the question that follows.

java
public class Test {
public static void main(String[] args) {
Stream.iterate(2, n -> n+1)
.map(n -> n + 2)
.filter(n -> n % 2 != 0)
.limit(4)
.forEach((x) -> System.out.print(x + " "));
}
}

What will the output be?

  1. A

    3 5 7 9

  2. B

    5 7 9 11

  3. C

    4 6 8 10

  4. D

    2 4 6 8

20 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java End Term 11 Dec 2022 Set ETD1-2 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 11 Dec 2022, in the September 2022 term, set ETD1-2: 23 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava End Term 11 Dec 2022 Set ETD1-2 at a glance
TermSeptember 2022 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ20
MSQ3
Official paperIIT M DIPLOMA AN1 EXAM ETD1 11 Dec 2022
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java