Quiz Space

Java End Term: 24 December 2023, Set ADD3 (September 2023 term)

Question 1

+4 marksOne correct option

Consider the Java program below.

Consider the Java code given below.

java
class Student {
String name;
public Student(String n) {
name = n;
}
public String toString() {
return "Name = " + name;
}
}
class Leader extends Student {
private int marks;
public Leader(String n, int m) {
super(n);
marks = m;
}
public Leader(Leader l) {
super(l.name);
marks = l.marks;
}
public String toString() {
return super.toString() + ", " + "Marks = " + marks;
}
}
public class College {
public static void main(String args[]) {
Student l1 = new Leader("Rohan", 97);
Student l2 = new Leader((Leader) l1);
l2.name = "Ananya";
System.out.println(l1 + "\n" + l2);
}
}

What will the output be?

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

Question 2

+4 marksOne correct option

Method Optional.ofNullable(T value) returns an Optional that describes the specific value, if non-null; otherwise returns an empty Optional.
Based on this description, consider the code given below, and answer the question that follows.

java
import java.util.*;
class GoldQC {
String type;
int karats;
public GoldQC(int k){
karats = k;
}
public GoldQC(String t, int k){
type = t;
karats = k;
}
}
public class Test {
public static void main(String[] args) {
var goldList = new ArrayList<GoldQC>();
goldList.add(new GoldQC("Ring", 24));
goldList.add(new GoldQC(18));
for (GoldQC g: goldList) {
System.out.print("karats = " + g.karats + ", type = ");
Optional<String> karatsValue = Optional.ofNullable(g.type);
karatsValue.ifPresentOrElse(t -> System.out.println(t),
() -> System.out.println("unknown")
);
}
}
}

Choose the correct option.

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

Question 3

+4 marksOne correct option

Consider the Java code give below.

java
abstract class Operation implements Runnable {
static int result = 0;
}
class AddOperation extends Operation {
public void run() {
if (result != 8) {
result = result + 3;
}
}
}
class MultiplyOperation extends Operation {
public void run() {
if (result != 9) {
result = result * 2;
}
}
}
public class MathOperations {
public static void main(String[] args) {
Operation addOp = new AddOperation();
Operation multiplyOp = new MultiplyOperation();
Thread t1 = new Thread(addOp);
Thread t2 = new Thread(multiplyOp);
t1.start();
t2.start();
System.out.println(Operation.result);
}
}

Choose the correct option.

  1. A

    The program will never generate the output: 0

  2. B

    The program will never generate the output: 3

  3. C

    The program will never generate the output: 6

  4. D

    The output can be 0 or 3 or 6 .

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 24 Dec 2023 Set ADD3 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 24 Dec 2023, in the September 2023 term, set ADD3: 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 24 Dec 2023 Set ADD3 at a glance
TermSeptember 2023 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions23
Marks100
Duration180 min
MCQ17
MSQ6
Official paperIIT M DIPLOMA FN EXAM FDD1 24 Dec 2023
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java