Quiz Space

Programming Concepts using Java Quiz 2: 10 July 2022 (May 2022 term)

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
class Address implements Cloneable{
private String city;
private int pinCode;
// constructor here to instantiate city, pinCode
public void setCity(String c){
city = c;
}
}
class Temple implements Cloneable{
private Address adr;
private String tempName;
// constructor here to instantiate adr, tempName
public Address getAddress(){
return adr;
}
public void setTempName(String t){
tempName = t;
}
public Temple clone() throws CloneNotSupportedException{
Temple t = (Temple) super.clone();
return t;
}
//Overrides the method toString()
// to return tempName + ":"+ city + ":" + pinCode;
}
public class Main{
public static void main(String[] args){
Temple t1 = new Temple(new Address("Madurai", 625001), "Meenakshi temple");
try{
Temple t2 = t1.clone();
t2.setTempName("Golden temple");
t2.getAddress().setCity("Amritsar");
System.out.println(t1);
System.out.println(t2);
}
catch(CloneNotSupportedException e){
System.out.println("Cloning not supported");
}
}
}

What will the output be?

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

Question 2

+3 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
public class Test{
public static void main(String[] args){
var bill_march = new LinkedHashMap<String, Integer>();
bill_march.put("suresh", 100);
bill_march.put("mukesh", 150);
bill_march.put("ganesh", 80);
bill_march.put("pranay", 200);
var bill_april = new LinkedHashMap<String, Integer>();
bill_april.put("suresh", 200);
bill_april.put("mukesh", 100);
bill_april.put("ganesh", 100);
bill_april.put("pranay", 100);
var totalBill = new LinkedHashMap<String, Integer>();
for(Map.Entry<String, Integer> e : bill_march.entrySet())
totalBill.put(e.getKey(), e.getValue());
for(Map.Entry<String, Integer> e : bill_april.entrySet())
totalBill.merge(e.getKey(), e.getValue(), (x, y) -> y + x);
System.out.println(totalBill);
}
}

Choose the correct option.

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

Question 3

+3 marksOne correct option

Consider the following code.

java
public class ArrayOperations{
public <T extends Comparable> T min(T[] arr){
// code for finding the minimum
}
public <T extends Number> T sum(T[] arr){
// code for finding the sum of elements
}
public <T> int count(T[] arr){
// code for finding the count of elements
}
}

What is the class ArrayOperations converted to after type erasure?

  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 10 Jul 2022 paper

The IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 10 Jul 2022, in the May 2022 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 10 Jul 2022 at a glance
TermMay 2022 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions15
Marks50
Duration120 min
MCQ11
MSQ4
Official paperIIT M DIPLOMA QUIZ2 EXAM QPE1 10 July 2022
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More Java