Quiz Space

Java End Term: 3 September 2023, Set QPD1-S2 (May 2023 term)

Question 1

+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
import java.util.stream.*;
public class Test {
public static void main(String[] args) {
Stream.iterate(0, n -> n+3).limit(6).filter(n -> n % 2 == 0)
.forEach(num -> System.out.print(num+" "));
}
}

What will the output be?

  1. A

    0 2 4 6 8 10

  2. B

    0 6 12

  3. C

    2 4 6 8 10 12

  4. D

    0 2 4 6

Question 2

+4 marksOne correct option

Consider the following java code

java
class Worker implements Cloneable{
String name;
public Worker(String n) {
name = n;
}
public Worker clone() throws CloneNotSupportedException{
return (Worker)super.clone();
}
}
class Work implements Cloneable{
String job;
Worker[] wk;
public Work(String j, Worker[] w) {
job = j;
wk = w;
}
public Work clone() throws CloneNotSupportedException{
Work t = (Work)super.clone();
t.wk = t.wk.clone();
return t;
}
}
public class Test {
public static void main(String[] args) throws CloneNotSupportedException{
Worker[] w1 = {new Worker("ABC"), new Worker("XYZ")};
Work obj1 = new Work("Painting", w1);
Work obj2 = obj1.clone();
Worker[] w2 = obj2.wk;
w2[0].name = "MNO";
obj2.job = "Printing";
System.out.println(obj1.job +" : " + obj1.wk[0].name);
System.out.println(obj2.job +" : " + obj2.wk[0].name);
}
}

What will the output be?

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

Question 3

+4 marksOne correct option

Consider the java code given below

java
class Employee{
private String name;
private double salary;
public Employee() {
this.salary = 40000.0;
}
public Employee(Employee e) {
this.name = e.name;
this.salary = e.salary;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getSalary() {
return salary;
}
}
public class Test{
public static void main(String[] args) {
Employee obj1 = new Employee();
Employee obj2 = obj1;
Employee obj3 = new Employee(obj1);
obj1.setSalary(50000.0);
obj1.setName("Anand");
obj2.setName("Karthik");
obj3.setName("Shannu");
System.out.println(obj1.getName() +": " + obj1.getSalary());
System.out.println(obj2.getName() +": " + obj2.getSalary());
System.out.println(obj3.getName() +": " + obj3.getSalary());
}
}

What will the output be?

  1. A

    Anand: 50000.0
    Anand: 50000.0
    Shannu: 40000.0

  2. B

    Karthik: 50000.0
    Karthik: 50000.0
    Shannu: 40000.0

  3. C

    Anand: 50000.0
    Karthik: 50000.0
    Shannu: 40000.0

  4. D

    Shannu: 40000.0
    Shannu: 40000.0
    Shannu: 40000.0

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 3 Sept 2023 Set QPD1-S2 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 3 Sept 2023, in the May 2023 term, set QPD1-S2: 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 3 Sept 2023 Set QPD1-S2 at a glance
TermMay 2023 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ18
MSQ5
Official paperIIT M DIPLOMA ET1 EXAM QPD1 S2 03 Sep
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java