0%
0 / 13 answered

Anatomy of a Class Practice Test

13 Questions
Question
1 / 13
Q1

Considering the Java class example below, which access modifier would you use for owner to ensure encapsulation?


public class BankAccount {

  // Fields represent state

  private String owner;

  private double balance;

  public BankAccount(String owner, double startingBalance) {

    this.owner = owner;

    balance = startingBalance;

  }

  public String getOwner() { return owner; }

}

// Encapsulation: hide fields, expose methods.

// Inheritance: subclasses can extend BankAccount.

// Polymorphism: overridden methods can change behavior.

Based on the class structure presented above, which modifier best fits owner?

Question Navigator