Question 7
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.
LINE 1 and LINE 2 generate compilation errors.
LINE 2 generates a compilation error, while others compile fine.
LINE 1, LINE 2, and LINE 3 generate compilation errors.
Only LINE 3 generates a compilation error.