uiz Space

May 2024 term · Programming Concepts using Java · BSCS2005

Programming Concepts using Java Quiz 1: 7 July 2024 (May 2024 term)

The IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 7 Jul 2024, in the May 2024 term: 15 questions for 100 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
15
Marks
100
Duration
120 min
MSQ
1
MCQ
14

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 7 July 2024 · No negative marking.

Question 1

+6 marksOne or more correct options

Which of the following statements is/are correct about activation records?

Select all that apply.

  1. A

    Return value link points to the start of the previous activation record.

  2. B

    An activation record is pushed into the stack when a function is called, and is popped out when the function returns.

  3. C

    The variables present in every activation record in the stack are in scope and are accessible.

  4. D

    The variables present in the topmost activation record of the stack are in scope and are accessible.

Show answer

Correct answers

  • B

    An activation record is pushed into the stack when a function is called, and is popped out when the function returns.

  • D

    The variables present in the topmost activation record of the stack are in scope and are accessible.

Question 2

+6 marksOne correct option

Match the following terms with their descriptions/properties.

  1. A

    1-B, 2-A, 3-C, 4-D, 5-E

  2. B

    1-A, 2-B, 3-D, 4-E, 5-C

  3. C

    1-C, 2-D, 3-B, 4-E, 5-A

  4. D

    1-D, 2-C, 3-E, 4-A, 5-B

Show answer

Correct answer

  • C

    1-C, 2-D, 3-B, 4-E, 5-A

Question 3

+6 marksOne correct option

Consider the Java code given below.

java
public class Test{
public static void main(String[] args){
int a[] = {10, 20};
int x = a[0];
for(int i : a){
switch(i){
case 10:
x = x + 10;
System.out.println(x);
break;
case 20:
x = x + 20;
System.out.println(x);
break;
default:
System.out.println(x);
}
}
}
}

What will the output be?

  1. A

    20
    30
    30

  2. B

    20
    40

  3. C

    20
    40
    60

  4. D

    10
    20
    40

Show answer

Correct answer

  • B

    20
    40

Question 4

+6 marksOne correct option

Consider the Java code given below.

java
interface Printer{
public default void print(){
System.out.println("Prints");
}
}
interface Scanner{
public default void scan(){
System.out.println("Scans");
}
}
class Device implements Printer, Scanner{
public void print(){
System.out.println("Color printing");
}
}
public class Test {
public static void main(String[] args) {
Printer p1 = new Device();
p1.print();
p1.scan(); //LINE 1
}
}

Choose the correct option.

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

Correct answer

  • C

Question 5

+6 marksOne correct option

Consider the Java code given below.

java
class Employee {
public void performTasks() {
System.out.println("Perform tasks");
}
}
class Manager extends Employee {
public void plan() {
System.out.println("Plan tasks");
}
public void monitor() {
System.out.println("Monitor employees");
}
}
class DeliveryHead extends Manager {
public void plan() {
System.out.println("Plan delivery operations");
}
}
public class Test {
public static void main(String[] args) {
Manager obj = new DeliveryHead();
obj.performTasks(); // LINE 1
obj.monitor();
obj.plan(); // LINE 2
}
}

Choose the correct option.

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

Correct answer

  • C

Question 6

+6 marksOne correct option

Consider the Java code given below.

java
class Bird {
private String species;
private String color;
public Bird(String species, String color) {
this.species = species;
this.color = color;
}
// ------- CODE SEGMENT ---------
}
public class Test {
public static void main(String[] args) {
Bird b1 = new Bird("Parrot", "Green");
Bird b2 = new Bird("Sparrow", "Brown");
System.out.println(b1 + "\n" + b2);
}
}

Choose the correct option to fill in the CODE SEGMENT so that the output is:
Parrot : Green
Sparrow : Brown

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

Correct answer

  • B

Question 7

+7 marksOne correct option

Consider the Java code given below. Identify the correct statement to fill in the blank at LINE 1, such that the output is: Eligible for Diploma

java
interface Eligibility {
void printEligibility();
}
class Student {
private double cgpa;
//Constructor to initialize instance variable
public Eligibility checkEligibility() {
if (cgpa > 6.0)
return new Eligible();
return new NotEligible();
}
private class Eligible implements Eligibility {
public void printEligibility() {
System.out.println("Eligible for Diploma");
}
}
private class NotEligible implements Eligibility {
public void printEligibility() {
System.out.println("Not eligible for Diploma");
}
}
}
public class Test {
public static void main(String[] args) {
Student s1 = new Student(5.5);
Student s2 = new Student(7.5);
----------------------------- //LINE 1
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 8

+7 marksOne correct option

Consider the code given below that checks whether two phones are the same. Method equals is overridden to compare two Phone objects as follows.

If two phones have the same brand and imeiNumber, then they are the same.

java
class Phone {
private String brand;
private int imeiNumber;
// Constructor to initialize instance variables
public boolean equals(Object obj) {
//CODE BLOCK
}
}
public class Test {
public static void main(String[] args) {
Phone p1 = new Phone("Samsung", 123456);
Phone p2 = new Phone("Samsung", 123456);
if (p1.equals(p2))
System.out.println("p1 and p2 are same");
else
System.out.println("p1 and p2 are different");
}
}

Choose the correct option(s) to fill in place of CODE BLOCK so that the output is:
p1 and p2 are same

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

Correct answer

  • D

Question 9

+7 marksOne correct option

Consider the Java code given below.

java
class TravelAgency{
String name;
String[] destinations;
public TravelAgency(String n, String[] d){
name = n;
destinations = d;
}
public TravelAgency(TravelAgency t){
this.name = t.name;
this.destinations = t.destinations;
}
}
public class Test{
public static void main(String[] args){
String[] d = {"Ooty", "Bali", "Thailand"};
TravelAgency t1 = new TravelAgency("RoamWorld", d);
TravelAgency t2 = new TravelAgency(t1);
t2.name= "ValleyTravel";
t2.destinations[0] = "Goa";
System.out.println(t1.name + "," +t1.destinations[0]);
System.out.println(t2.name + "," +t2.destinations[0]);
}
}

What will the output be?

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

Correct answer

  • B

Question 10

+7 marksOne correct option

Consider the Java code given below.

java
class Screen {
void showContent() {
System.out.println("Display on screen");
}
}
class TV extends Screen {
void showContent() {
super.showContent();
System.out.println("Display on TV");
}
void showContent(String s) {
System.out.println("Display on TV: " + s);
}
}
class Monitor extends TV {
void showContent() {
super.showContent();
System.out.println("Display on monitor");
}
void showContent(String s) {
System.out.println("Display on monitor: " + s);
}
}
class Test {
public static void main(String[] args) {
TV obj = new Monitor(); // LINE 1
obj.showContent();
obj.showContent("News"); // LINE 2
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 11

+7 marksOne correct option

Consider the Java code given below.

java
1 interface Coolable {
2 public void startCooling();
3 public void stopCooling();
4 }
5 interface TemperatureAdjustable {
6 public void adjustTemperature();
7 default void displayTemperature() {
8 System.out.println("Temperature is adjustable.");
9 }
10 }
11 class AirConditioner implements Coolable, TemperatureAdjustable {
12 public void startCooling() {
13 System.out.println("Cooling started.");
14 }
15 public void stopCooling() {
16 System.out.println("Cooling stopped.");
17 }
18 }

Choose the correct option regarding the above code.

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

Correct answer

  • C

Question 12

+7 marksOne correct option

Consider the Java code given below.

java
interface Singable {
default void sing() {
System.out.println("Sings");
}
public void perform();
}
abstract class Musician implements Singable {
public void sing() {
System.out.println("Sings song");
}
}
class LeadSinger extends Musician {
public void perform() {
System.out.println("Leads group");
}
}
public class Test {
public static void main(String[] args) {
Singable obj1 = new LeadSinger(); // LINE 1
Musician obj2 = new LeadSinger();
obj2.sing();
obj2.perform(); // LINE 2
}
}

Choose the correct option.

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

Correct answer

  • A

Question 13

+7 marksOne correct option

Consider the Java code given below.

java
class Player {
private String name;
private int jerseyNumber;
public Player(String nm){
name = nm;
}
public Player(int number){
jerseyNumber = number;
}
public Player(String nm, int number) {
name = nm;
jerseyNumber = number;
}
public String toString() {
return "Name: " + name + ", Jersey Number: " + jerseyNumber;
}
}
class Captain extends Player {
private String team;
// ------- CODE BLOCK ---------
public String toString() {
return super.toString() + ", Team: " + team;
}
}

Choose the correct option to fill in place of CODE BLOCK to instantiate instance variables of class Captain

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

Correct answer

  • B

Question 14

+7 marksOne correct option

Consider the Java code given below.

java
interface Iterator {
public boolean has_next();
public Object get_next();
}
abstract class Printable {
public abstract void print();
}
class BankAccount extends Printable {
private String accountName;
private double balance;
public BankAccount(String aN, double b) {
//initialize accountname and balance
}
public void print() {
System.out.println(accountName + ", " + balance);
}
}
class BankAccountList {
private final int limit = 3;
private BankAccount[] list;
public BankAccountList(BankAccount[] accounts) {
this.list = accounts;
}
private class BankAccountIter implements Iterator {
private int indx;
public BankAccountIter() {
//constructor
}
public boolean has_next() {
//if next element available in list return true;else false
}
public Object get_next() {
//return next element from list
}
}
public Iterator getIterator() {
return new BankAccountIter();
}
}
public class Test{
public static void main(String[] args) {
BankAccountList.BankAccount[] accounts = {
new BankAccountList.BankAccount("Priya", 500),
new BankAccountList.BankAccount("Ravi", 1000),
new BankAccountList.BankAccount("Suresh", 1500)
};
BankAccountList bList = new BankAccountList(accounts);
Iterator iter = bList.getIterator();
while(iter.has_next()) {
------------------; //LINE 1
}
}
}

Identify the appropriate statement to fill in the blank at LINE 1, such that the output is:
Priya, 500
Ravi, 1000
Suresh, 1500

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

Correct answer

  • A

Question 15

+8 marksOne correct option

Consider the Java code given below.

java
class Appliance {
private int code;
private static double basePower = 100;
public Appliance(int c) {
code = c;
}
public final double electricityFare() {
return basePower*2;
}
}
class Cooler extends Appliance {
public Cooler(int x) {
super(x);
}
public final double electricityFare() { //LINE 1
return basePower*3; //LINE 2
}
}
public class Test {
public static void main(String[] args) {
Appliance d1 = new Cooler(101); // LINE 3
Cooler c1 = new Appliance(105); // LINE 4
d1.electricityFare();
c1.electricityFare();
}
}

Which of the following statements is FALSE?

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

Correct answer

  • C