uiz Space

May 2025 term · Programming Concepts using Java · BSCS2005

Programming Concepts using Java Quiz 1: 13 July 2025 (May 2025 term)

The IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 13 Jul 2025, in the May 2025 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
MCQ
11
MSQ
4

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 13 July 2025 · No negative marking.

Question 1

+7 marksOne correct option

Consider the following Java program. When the call stack reaches its maximum depth, which method will be at the top of the call stack?

java
class Example {
public void methodA(int x) {
if (x > 0) {
methodB(x - 1);
}
}
public void methodB(int y) {
if (y > 0) {
methodC(y - 1);
}
}
public void methodC(int z) {
if (z > 0) {
methodA(z - 1);
}
}
}
class TestCallStack {
public static void main(String[] args) {
Example e = new Example();
e.methodA(3);
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 2

+7 marksOne correct option

Consider the Java code below.

java
class Account {
public void login() {
System.out.println("Basic login");
}
}
class User extends Account {
public void login() {
super.login();
System.out.println("User login");
}
public void login(String code) {
System.out.println("User login with code: " + code);
}
}
class Admin extends User {
public void login() {
super.login();
System.out.println("Admin login");
}
public void login(String code) {
System.out.println("Admin login with code: " + code);
}
}
public class Test {
public static void main(String[] args) {
User obj = new Admin(); // LINE 1
obj.login();
obj.login("9999");
}
}

Choose the correct option.

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

Correct answer

  • A

Question 3

+7 marksOne correct option

Consider the Java code given below.

java
class Animal {
private String name;
public Animal(String n) {
name = n;
}
public String toString() {
return "Name: " + name;
}
}
class Dog extends Animal {
private String breed;
public Dog(String n, String b) {
//LINE 1
breed = b;
}
public String toString() {
return super.toString() + ", Breed: " + breed;
}
}
public class Test {
public static void main(String[] args) {
Animal dog = new Dog("Rocky", "Golden Retriever");
System.out.println(dog);
}
}

Choose the correct option to be filled in place of LINE 1 so that the output is:

Name: Rocky, Breed: Golden Retriever

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

Correct answer

  • B

Question 4

+7 marksOne correct option

Consider the Java code given below:

java
public class SwitchTest {
public static void show() {
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
System.out.print("Zero ");
break;
case 1:
System.out.print("One ");
case 2:
System.out.print("Two ");
break;
default:
System.out.print("Default ");
}
System.out.println();
}
}
public static void main(String[] args) {
show();
}
}

What will the output be?

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

Correct answer

  • A

Question 5

+7 marksOne correct option

Consider the Java program below. Choose the correct option to fill in place of the CODE BLOCK so that the output is:

text
Viewing balance
Calculating interest for SavingsAccount
Offering premium benefits
java
class Account {
void viewBalance() {
System.out.println("Viewing balance");
}
}
class SavingsAccount extends Account {
void calculateInterest() {
System.out.println("Calculating interest for SavingsAccount");
}
}
class PremiumSavingsAccount extends SavingsAccount {
void offerPremiumBenefits() {
System.out.println("Offering premium benefits");
}
}
public class BankApp {
public static void main(String[] args) {
SavingsAccount acc = new PremiumSavingsAccount();
acc.viewBalance();
acc.calculateInterest();
// CODE BLOCK
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 6

+7 marksOne correct option

Consider the Java code given below.

java
interface Printable {
void print();
}
class Book implements Printable {
public void print() {
System.out.println("Printing Book");
}
}
class Magazine implements Printable {
public void print() {
System.out.println("Printing Magazine");
}
}
class PrintQueue {
private Object[] printables = {new Book(), new Magazine()};
public void startPrinting() {
for (int i = 0; i < printables.length; i++) {
// LINE 1
}
}
}
public class PrintTest {
public static void main(String[] args) {
PrintQueue pq = new PrintQueue();
pq.startPrinting();
}
}

Identify the appropriate option to fill in place of LINE 1 such that the output is:

text
Printing Book
Printing Magazine
  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.

java
interface Shape {
public default void draw() {
System.out.println("Drawing a shape");
}
}
class Circle implements Shape { // LINE 1
}
class Square implements Shape {
public void draw() {
System.out.println("Drawing a square");
}
}
public class DrawingTest {
public static void main(String[] args) {
Shape s1 = new Circle();
s1.draw(); // LINE 2
Shape s2 = new Square();
s2.draw();
}
}

Choose the correct option.

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

Correct answer

  • B

Question 8

+7 marksOne correct option

Consider the code given below.

java
interface Navigator {
boolean hasNext();
Object next();
}
abstract class Displayable {
public abstract void show();
}
class BookShelf {
private class Book extends Displayable {
private String title;
public Book(String t) {
title = t;
}
public void show() {
System.out.print(title + ", ");
}
}
private class BookIterator implements Navigator {
private int index;
public BookIterator() {
//Constructor
}
public boolean hasNext() {
// Check if there is a next book
}
public Object next() {
// Return the next book
}
}
public Navigator getNavigator() {
return new BookIterator();
}
private Book[] books = {new Book("Swami"), new Book("Pyre"),
new Book("Palace") };
}
public class LibraryTest {
public static void main(String[] args) {
BookShelf shelf = new BookShelf();
Navigator nav = shelf.getNavigator();
while (nav.hasNext()) {
___________________________________; // LINE 1
}
}
}

Identify the appropriate statement to fill in the blank at LINE 1, such that the output is: Swami, Pyre, Palace,

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

Correct answer

  • A

Question 9

+6 marksOne correct option

Consider the Java code given below.

java
class Book {
private String title;
private int price;
public Book(String t, int p) {
title = t;
price = p;
}
public Book(Book ot) {
title = ot.title;
price = ot.price;
}
public void setPrice(int p) {
price = p;
}
public String toString() {
return "Title: " + title + ", Price: " + price;
}
}
public class Test {
public static void main(String[] args) {
Book b1 = new Book("Java", 500);
Book b2 = b1;
Book b3 = new Book(b1);
b2.setPrice(600);
System.out.println("b1: " + b1);
System.out.println("b3: " + b3);
}
}

What will the output be?

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

Correct answer

  • C

Question 10

+6 marksOne correct option

Consider the following Java code.

java
interface Printer {
default void print() {
System.out.println("Printing document");
}
}
interface Scanner {
default void print() {
System.out.println("Scanning document");
}
}
class MultiFunctionDevice implements Printer, Scanner { // LINE 1
}
public class OfficeTest {
public static void main(String[] args) {
MultiFunctionDevice mfd = new MultiFunctionDevice();
mfd.print(); // LINE 2
}
}

Choose the correct option.

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

Correct answer

  • C

Question 11

+6 marksOne correct option

Consider the Java code given below.

java
class Employee {
public void show() {
System.out.println("Employee::show()");
}
}
class Department {
public Manager getManager() {
return new Manager();
}
private class Manager extends Employee {
public void show() {
System.out.println("Manager::show()");
}
}
}
public class CompanyTest {
public static void main(String[] args) {
Department dept = new Department();
// LINE 1
managerObj.show();
}
}

Choose the correct option for LINE 1 such that the program generates the following output.

Manager::show()

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

Correct answer

  • A

Question 12

+6 marksOne or more correct options

Which of the following statements correctly describe interface and specification in software components?

Select all that apply.

  1. A

    An interface includes function signatures, arguments, and return types.

  2. B

    Specification refers to the intended input-output behavior of the component.

  3. C

    Interface helps describe how a component is implemented internally.

  4. D

    A good specification language should balance abstraction and detail.

Show answer

Correct answers

  • A

    An interface includes function signatures, arguments, and return types.

  • B

    Specification refers to the intended input-output behavior of the component.

  • D

    A good specification language should balance abstraction and detail.

Question 13

+6 marksOne or more correct options

Which among the following statements is/are true about activation records?

Select all that apply.

  1. A

    Multiple activation records of the same function can exist on the stack during recursion.

  2. B

    Activation records created for functions are allocated in heap.

  3. C

    The return value link in an activation record identifies the memory location for storing the function’s return value.

  4. D

    The lifetime of a variable extends beyond the removal of its activation record from the stack.

Show answer

Correct answers

  • A

    Multiple activation records of the same function can exist on the stack during recursion.

  • C

    The return value link in an activation record identifies the memory location for storing the function’s return value.

Question 14

+7 marksOne or more correct options

Consider the Java code given below.

java
class Author {
private String name;
public Author(String na){
name = na;
}
public String toString(){
return "authored by " + name;
}
}
class Book {
private String title;
private Author author;
public Book(String t, Author a){
title = t;
author = a;
}
***-----------------------***
* CODE SEGMENT HERE *
***-----------------------***
}
public class Library {
public static void main(String[] args){
Author auth = new Author("R.K. Narayan");
Book book = new Book("Malgudi Days", auth);
System.out.println(book);
}
}

Choose the correct option(s) to fill in the CODE SEGMENT so that the output is:

Malgudi Days authored by R.K. Narayan

Select all that apply.

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

Correct answers

  • A
  • C

Question 15

+7 marksOne or more correct options

Consider the Java code given below.

java
class Doctor {
protected int patientsTreated;
protected static double consultationFee = 300;
public Doctor(int p) {
patientsTreated = p;
}
public final double calculateIncome() {
return patientsTreated * consultationFee;
}
}
class SpecialistDoctor extends Doctor {
public SpecialistDoctor(int p) {
super(p);
}
public final double calculateIncome() { // LINE 1
return (patientsTreated * consultationFee) + 2000; // LINE 2
}
}
public class Hospital {
public static void main(String[] args) {
Doctor d1 = new SpecialistDoctor(10); // LINE 3
SpecialistDoctor sd1 = new Doctor(12); // LINE 4
d1.calculateIncome();
sd1.calculateIncome();
}
}

Which of the following statements are correct?

Select all that apply.

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

Correct answers

  • A
  • D