Quiz Space

Programming Concepts using Java · Quiz 2 · 23 Nov 2025 · September 2025 term

Question 7: Consider two Java files located in two different packages…

Question 7

+7 marksOne correct option

Consider two Java files located in two different packages as shown below.
Account.java:
package com.bank;
public class Account {
int accountNumber = 1001;
private double balance = 5000.0;
protected void deposit(double amount) {
balance += amount;
System.out.println("Deposited: " + amount);
}
public void displayBalance() {
System.out.println("Balance: " + balance);
}
}
SavingsAccount.java:
package com.customer;
import com.bank.Account;
public class SavingsAccount extends Account {
public static void main(String[] args) {
SavingsAccount sa = new SavingsAccount();
System.out.println(sa.accountNumber); // LINE 1
System.out.println(sa.balance); // LINE 2
sa.deposit(1000); // LINE 3
sa.displayBalance(); // LINE 4
}
}
Choose the correct option.

  1. A

    LINE 1 and LINE 2 generate compilation errors.

  2. B

    LINE 2 generates a compilation error, while others compile fine.

  3. C

    LINE 1, LINE 2, and LINE 3 generate compilation errors.

  4. D

    Only LINE 3 generates a compilation error.

Show answer

Correct answer

  • A

    LINE 1 and LINE 2 generate compilation errors.

Question 7 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 23 Nov 2025, in the September 2025 term (IIT M DIPLOMA AN EXAM QDD2 23 Nov 2025 NEW). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both…
  2. Q2Consider the code given below.\ interface Vehicle {\ public abstract double getFuelEfficiency();\ }\ class Car implemen…
  3. Q3Consider the Java code given below. Choose the correct option to fill in place of CODE BLOCK so that the output is: Ple…
  4. Q4Consider the following Java code. What will the output be?
  5. Q5Consider the Java code given below. How does class MathUtils look after type erasure?
  6. Q6Consider the Java code given below.\ interface Discount{\ public void apply(int price);\ }\ class ShoppingCart{\ public…
  7. Q8Consider the Java code given below.\ interface Shape {\ void draw();\ }\ class ShapeFactory {\ private String type;\ pu…
  8. Q9The merge(K key, V value, remappingFunction) function is defined as: If the specified key is not already associated wit…
  9. Q10Consider the Java code given below that prints the average rating of a set of Rateable objects. From among the options,…
  10. Q11Consider the code given below. Identify the appropriate option(s) to fill in the blank at LINE 1 such that the output o…
  11. Q12Consider the Java code given below.\ class Student {\ private int marks;\ public Student(int marks){\ assert marks >= 0…
  12. Q13Consider the Java code given below. Choose the correct option.
  13. Q14Consider the Java code given below.\ interface Chargeable {\ void showChargeStatus();\ }\ class Laptop implements Charg…
  14. Q15Consider the Java code given below.\ class NegativeBalanceException extends Exception {\ public NegativeBalanceExceptio…