uiz Space

September 2025 term · Programming Concepts using Java · BSCS2005

Programming Concepts using Java Quiz 1: 26 October 2025 (September 2025 term)

The IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 26 Oct 2025, in the September 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
13
MSQ
2

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 26 Oct 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 Demo {
public void alpha(int n) {
if (n > 0) {
beta(n - 1);
}
}
public void beta(int n) {
if (n > 0) {
gamma(n - 1);
}
}
public void gamma(int n) {
if (n > 0) {
gamma(n - 1);
}
}
}
class TestStack {
public static void main(String[] args) {
Demo d = new Demo();
d.alpha(3);
}
}
  1. A

    alpha ()

  2. B

    beta ()

  3. C

    gamma ()

  4. D

    main ()

Show answer

Correct answer

  • C

    gamma ()

Question 2

+7 marksOne correct option

Consider the following Java program.

java
public class ArraySquare {
public static int[] square(int[] a){
for(int i = 0; i < a.length; i++){
a[i] = a[i] * a[i];
}
return a;
}
public static void main(String[] args) {
int[] arr = {2,3,4};
int[] b = square(arr);
System.out.println(arr[1] + b[2]);
}
}

What will the output be?

  1. A

    21

  2. B

    28

  3. C

    25

  4. D

    16

Show answer

Correct answer

  • C

    25

Question 3

+7 marksOne correct option

Consider the code given below that searches for a Book in an array. Two Book objects are considered equal if they have the same title and isbn. The equals method needs to be overridden so that the search works correctly.

java
class Book {
private String title;
private String isbn;
//constructor to initialize the instance variables
public boolean equals(Object obj) {
// CODE BLOCK
}
}
public class Test {
public static void main(String[] args) {
Book[] library = {
new Book("Effective Java", "111"),
new Book("Clean Code", "222"),
new Book("Design Patterns", "333")
};
Book target = new Book("Clean Code", "222");
boolean found = false;
for (int i = 0; i < library.length; i++) {
if (library[i].equals(target)) {
found = true;
break;
}
}
if (found)
System.out.println("Book Found");
else
System.out.println("Book Not Found");
}
}

Choose the correct option to fill in place of CODE BLOCK so that the output is:

Book Found

  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
class Person {
private String name;
public Person(String nm) {
name = nm;
}
public String toString(){
return name;
}
}
class Student extends Person {
private int rollNo;
// ------- CODE BLOCK ---------
public String toString(){
return super.toString() +" : "+ rollNo;
}
}
public class Test {
public static void main(String[] args) {
Student s1 = new Student("Aman", 101);
System.out.println(s1);
}
}

Choose the correct option to fill in place of CODE BLOCK so that it produces the given output:

Aman : 101

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

Correct answer

  • D

Question 5

+7 marksOne correct option

Consider the Java code below.

java
class Shape {
public void area() {
System.out.println("Generic Shape");
}
}
class Circle extends Shape {
public void area() {
super.area();
System.out.println("Circle area");
}
public void area(double r) {
System.out.println("Circle area with radius: " + r);
}
}
class Cylinder extends Circle {
public void area() {
super.area();
System.out.println("Cylinder area");
}
public void area(double r, double h) {
System.out.println("Cylinder area with radius " + r +
" and height " + h);
}
}
public class Test {
public static void main(String[] args) {
Circle obj = new Cylinder(); // LINE 1
obj.area();
obj.area(5.0);
}
}

Choose the correct option.

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

Correct answer

  • A

Question 6

+7 marksOne correct option

Consider the Java code given below.

java
class Library {
String name;
String[] books;
public Library(String n, String[] b) {
name = n;
books = b;
}
public Library(Library l) {
name = l.name;
books = l.books;
}
}
public class TestLibrary {
public static void main(String[] args) {
String[] b = {"Java", "Python", "C++"};
Library l1 = new Library("CityLibrary", b);
Library l2 = new Library(l1);
l2.name = "TownLibrary";
l2.books[1] = "JavaScript";
System.out.println(l1.name + "," + l1.books[1]);
System.out.println(l2.name + "," + l2.books[1]);
}
}

What will the output be?

  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
class Employee {
private int empId;
private static double bonusRate = 2.0;
public Employee(int id) {
empId = id;
}
public final double calculateBonus() {
return bonusRate * 1000;
}
}
class Manager extends Employee {
public Manager(int id) {
super(id);
}
public final double calculateBonus() { // LINE 1
return (bonusRate + 1.0) * 1000; // LINE 2
}
}
public class EmployeeTest {
public static void main(String[] args) {
Manager m1 = new Employee(101); // LINE 3
Employee e1 = new Manager(102); // LINE 4
System.out.println(e1.calculateBonus());
System.out.println(m1.calculateBonus());
}
}

Which of the following statements is FALSE?

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

Correct answer

  • D

Question 8

+7 marksOne correct option

Consider the code given below.

java
interface Shape {
public double area();
public static void printArea(double a) {
System.out.println("Area is : " + a);
}
}
class Circle implements Shape {
private double radius;
public Circle(double r) {
radius = r;
}
public double area() {
return Math.PI * radius * radius;
}
}
public class TestShape {
public static void main(String[] args) {
Circle c = new Circle(2);
____________________________________ //LINE 1
}
}

Identify the appropriate option to fill in the blank at LINE 1, such that the output is:

Area is : 12.566370614359172

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

Correct answer

  • C

Question 9

+6 marksOne correct option

Consider the Java code given below.

java
interface Notifiable {
void notifyUser();
}
class DeliveryApp implements Notifiable {
public void placeOrder() {
DeliveryService d = new DeliveryService(this); // LINE 1
System.out.println("Order placed");
d.processOrder();
}
public void notifyUser() {
System.out.println("Order delivered");
}
}
class DeliveryService {
Notifiable client;
public DeliveryService(Notifiable c) {
client = c;
}
public void processOrder() {
System.out.println("Processing order");
client.notifyUser(); // LINE 2
}
}
public class Test {
public static void main(String[] args) {
DeliveryApp app = new DeliveryApp();
app.placeOrder();
}
}

Choose the correct option.

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

Correct answer

  • D

Question 10

+6 marksOne correct option

Consider the following Java code.

java
interface Camera {
default void start() {
System.out.println("Camera started");
}
}
abstract class MusicPlayer {
public void start() {
System.out.println("Music started");
}
}
class SmartPhone extends MusicPlayer implements Camera { // LINE 1
}
public class TestSmartPhone {
public static void main(String[] args) {
SmartPhone sp = new SmartPhone();
sp.start(); // LINE 2
}
}

Choose the correct option.

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

Correct answer

  • B

Question 11

+6 marksOne correct option

Consider the Java code given below.

java
class Payment {
public void process() {
System.out.println("Processing generic payment");
}
}
class UpiPayment extends Payment {
public void process() {
System.out.println("Processing UPI payment");
}
public void showUpiId() {
System.out.println("UPI ID: riya@upi");
}
}
public class TestPayment {
public static void main(String[] args) {
Payment p = new UpiPayment();
p.process();
p.showUpiId(); // LINE 1
}
}

Choose the correct option.

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

Correct answer

  • A

Question 12

+8 marksOne correct option

Consider the Java code given below.

java
interface Device {
void start();
default void info() {
System.out.println("Generic Device");
}
}
interface SmartDevice extends Device {
default void info() {
System.out.println("Smart Device");
}
}
class SmartPhone implements SmartDevice {
public void start() {
System.out.println("Phone starting...");
}
public void info() {
System.out.println("SmartPhone with 5G");
}
}
public class Test {
public static void main(String[] args) {
Device d = new SmartPhone(); // LINE 1
SmartDevice sd = new SmartPhone(); // LINE 2
d.start();
d.info(); // LINE 3
sd.start();
sd.info(); // LINE 4
}
}

Choose the correct option.

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

Correct answer

  • A

Question 13

+5 marksOne correct option

Consider the Java code segment given below.

java
class BookList {
private class Book implements Printable {
private String title;
public Book(String t) {
title = t;
}
public void print() {
System.out.println("Book: " + title);
}
}
private class BookIterator implements Iterable {
private int idx;
public BookIterator() {
idx = -1;
}
public boolean has_next() {
return idx < list.length - 1;
}
public Printable get_next() {
idx++;
return list[idx];
}
}
public Iterable getIterator() {
return new BookIterator();
}
private Book[] list = {
new Book("Java Basics"), new Book("Data Structures"),
new Book("Design Patterns"), new Book("Algorithms"),
new Book("Software Engineering")
};
}
public class TestBooks {
public static void main(String[] args) {
BookList myBooks = new BookList();
Iterable it = myBooks.getIterator();
while(it.has_next()) {
it.get_next().print();
}
}
}

From the following options, identify the appropriate definitions of Iterable and Printable.

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

Correct answer

  • B

Question 14

+6 marksOne or more correct options

Which of the following statements correctly describe static typing and dynamic typing?

Select all that apply.

  1. A

    In dynamic typing, the type of a variable is determined at runtime and may change with the value assigned.

  2. B

    Dynamic typing requires explicit declaration of variable names and their types before use.

  3. C

    Static typing allows the compiler to catch type errors early and perform type- based optimizations.

  4. D

    In static typing, variables can freely change their type at runtime by assigning values of different types.

Show answer

Correct answers

  • A

    In dynamic typing, the type of a variable is determined at runtime and may change with the value assigned.

  • C

    Static typing allows the compiler to catch type errors early and perform type- based optimizations.

Question 15

+7 marksOne or more correct options

Consider the Java program below.

java
class Address {
private String city;
private String country;
public Address(String c, String co) {
city = c;
country = co;
}
public String toString() {
return city + ", " + country;
}
}
class Person {
private String name;
private Address addr;
public Person(String n, Address a) {
name = n;
addr = a;
}
// ----------- CODE BLOCK -----------
}
public class TestPerson {
public static void main(String[] args) {
Person p = new Person("Riya", new Address("Bangalore", "India"));
System.out.println(p);
}
}

Identify the correct option(s) to fill in place of CODE BLOCK so that the output is:

Person: Riya, Address: Bangalore, India

Select all that apply.

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

Correct answers

  • B
  • D