Quiz Space

Java End Term: 3 September 2023, Set QPD1-S1 (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(8, n -> n-1)
.map(n -> n + 2)
.filter(n -> n % 3 == 0)
.limit(4)
.forEach((x) -> System.out.print(x + " "));
}
}

What will the output be?

  1. A

    12 9 6 3

  2. B

    9 6 3 0

  3. C

    10 7 4 1

  4. D

    7 4 1 0

Question 2

+4 marksOne correct option

Consider the following java code

java
class Player implements Cloneable{
String name;
public Player(String n) {
name = n;
}
public Player clone() throws CloneNotSupportedException{
return (Player)super.clone();
}
}
class Team implements Cloneable{
String teamname;
Player[] ply;
public Team(String tn, Player[] p) {
teamname = tn;
ply = p;
}
public Team clone() throws CloneNotSupportedException{
Team t = (Team)super.clone();
t.ply = t.ply.clone();
return t;
}
}
public class Test {
public static void main(String[] args) throws CloneNotSupportedException{
Player[] p1 = {new Player("Nikita"), new Player("Ram")};
Team t1 = new Team("Orange", p1);
Team t2 = t1.clone();
Player[] p2 = t2.ply;
p2[0].name = "Srikanth";
t2.teamname = "Mango";
System.out.println(t1.teamname +" : " + t1.ply[0].name);
System.out.println(t2.teamname +" : " + t2.ply[0].name);
}
}

What will the output be?

  1. A

    Orange : Srikanth
    Orange : Srikanth

  2. B

    Mango : Srikanth
    Orange : Srikanth

  3. C

    Mango : Nikita
    Orange : Srikanth

  4. D

    Orange : Srikanth
    Mango : Srikanth

Question 3

+4 marksOne correct option

Consider the java code given below

java
class Instructor{
private String name;
private double salary;
public Instructor() {
this.salary = 40.0;
}
public Instructor(Instructor t) {
this.name = t.name;
this.salary = t.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) {
Instructor obj1 = new Instructor();
Instructor obj2 = obj1;
Instructor obj3 = new Instructor(obj1);
obj1.setSalary(50.0);
obj1.setName("Suresh");
obj2.setName("Ram");
obj3.setName("Ravi");
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

    Suresh: 50.0
    Ram: 50.0
    Ravi: 40.0

  2. B

    Ram: 50.0
    Ram: 50.0
    Ravi: 40.0

  3. C

    Ram: 50.0
    Ravi: 40.0
    Ravi: 40.0

  4. D

    Ravi: 50.0
    Ram: 50.0
    Ravi: 40.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-S1 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-S1: 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-S1 at a glance
TermMay 2023 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ19
MSQ4
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