Quiz Space

Java End Term: 7 August 2022, Set QPB1 (May 2022 term)

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
class Student{
private String name;
public Student(String n){
this.name = n;
}
public Student(Student s){
this.name = s.name;
}
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
}
public class Test{
public static void main(String[] args){
Student s1 = new Student("Ram");
Student s2 = s1;
Student s3 = new Student(s1);
s1.setName("Rahul");
System.out.println("s2.name : " + s2.getName());
System.out.println("s3.name : " + s3.getName());
}
}

What will the output be?

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

Question 2

+3 marksOne correct option

Assume that the file “data.txt” contains the following two lines of text.

text
india is my country
india is my country

Consider the code given below.

java
import java.io.*;
import java.util.*;
public class FileTest {
public static void main(String[] args) {
try {
var in = new FileInputStream("data.txt");
var sc = new Scanner(in);
var data = new TreeSet<String>();
while(sc.hasNext()) {
data.add(sc.next()+" ");
}
for(String str:data)
System.out.print(str);
}
catch (FileNotFoundException e) {
System.out.println("File does not exist.");
}
catch (IOException e) {
System.out.println("Error in writing a file.");
}
}
}

What will the output be?

  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 Main{
public static void main(String[] args){
Integer[] a = {10, 8, 22, 13, 7};
Stream.of(a).map((i) -> i - 10)
.filter((i) -> i% 2 == 0)
.forEach((x) -> System.out.println(x));
}
}

What will the output be?

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

19 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 7 Aug 2022 Set QPB1 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 7 Aug 2022, in the May 2022 term, set QPB1: 22 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 7 Aug 2022 Set QPB1 at a glance
TermMay 2022 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions22
Marks100
Duration180 min
MCQ15
MSQ7
Official paperIIT M FOUNDATION DIPLOMA ENDTERM QPD1 07 Aug 2022 IBA NS
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java