Quiz Space

Java Quiz 2: 3 December 2023 (September 2023 term)

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
public class SetIteratorTest {
public static void main(String[] args) {
var set1 = new HashSet<String>();
set1.add("Cherry");
set1.add("Banana");
set1.add("Apple");
set1.add("Date");
var set2 = new TreeSet<String>(set1);
Iterator<String> it1 = set1.iterator();
Iterator<String> it2 = set2.iterator();
while (it1.hasNext()) {
System.out.println(it1.next());
}
while (it2.hasNext()) {
System.out.println(it2.next());
}
}
}

Choose the correct option.

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

Question 2

+3 marksOne correct option

Consider the Java code given below.

java
interface Language{
void display();
}
class French implements Language{
public void display() {
System.out.println("French Language");
}
}
class English implements Language{
public void display() {
System.out.println("English Language");
}
}
class LanguageList{
private Object[] LArr = {new French(), new English()};
public void getInfo(){
for(int i = 0; i < LArr.length; i++){
//LINE 1
}
}
}
public class Test{
public static void main(String[] args) {
LanguageList aList = new LanguageList();
aList.getInfo();
}
}

Identify the appropriate option to fill in place of LINE 1 such that the output is
French Language
English Language

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

Question 3

+3 marksOne correct option

Consider the following Java code.

java
import java.util.stream.*;
public class Test {
public static void main(String[] args) {
String[] colors = {"red", "green", "blue", "yellow"};
Stream.of(colors).map((color) -> color.length())
.filter((length) -> length % 2 == 0)
.forEach((x) -> System.out.println(x));
}
}

What will the output be?

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

12 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 Quiz 2 3 Dec 2023 paper

The IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 3 Dec 2023, in the September 2023 term: 15 questions for 50 marks in 120 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 Quiz 2 3 Dec 2023 at a glance
TermSeptember 2023 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions15
Marks50
Duration120 min
MCQ11
MSQ4
Official paperIIT M DIPLOMA AN2 EXAM QDD2 03 Dec 2023
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More Java