Quiz Space

Programming Concepts using Java Quiz 2: 6 August 2023 (May 2023 term)

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
interface Computable{
void compute();
}
class Phone implements Computable{
public void compute() {
System.out.println("Phone compute");
}
}
class Laptop implements Computable{
public void compute() {
System.out.println("Laptop compute");
}
}
class DeviceList{
private Object[] cArr = {new Phone(), new Laptop()};
public void getCompute(){
for(int i = 0; i < cArr.length; i++){
//LINE 1
}
}
}
public class Test{
public static void main(String[] args) {
DeviceList dList = new DeviceList();
dList.getCompute();
}
}

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

Phone compute
Laptop compute

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

Question 2

+3 marksOne correct option

Consider the Java code given below.

java
public class Example{
public <T extends Comparable> void sortArray(T[] obj){
// Sorts obj
}
public <T> void elementDisplay(T[] arr){
// Displays the elements of arr
}
public <T extends Number> T sum(List<T> lst){
// Returns the sum of elements of lst
}
}

How does class Example look after type erasure?

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

Question 3

+3 marksOne correct option

Consider the code given below

java
interface Shape{
public abstract int area();
}
class Square implements Shape, Cloneable{
int side;
public Square(int s){
side = s;
}
public int area(){
return side * side;
}
public Square clone() throws CloneNotSupportedException{
return (Square)super.clone();
}
}
public class Test{
public static void main(String[] args){
Square s1 = new Square(5);
try{
Square s2 = s1.clone();
s1.side = 3;
System.out.print(s1.area() + s2.area());
}
catch(CloneNotSupportedException e){
System.out.println("Cloning not supported");
}
}
}

What will the output be?

  1. A

    18

  2. B

    50

  3. C

    34

  4. D

    Cloning not supported

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 6 Aug 2023 paper

The IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 6 Aug 2023, in the May 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 6 Aug 2023 at a glance
TermMay 2023 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions15
Marks50
Duration120 min
MCQ10
MSQ5
Official paperIIT M FOUNDATION AN2 EXAM QPF2 06 Aug 2023
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More Java