~/ learn/ comp-308/ cards/ Reuse: Composition, Inheritance & Polymorphism
1 of 30

Declare a package and a public class with a private field

Declare a package and a public class with a private field

Answer

package bank; public class Account { private double balance; public double getBalance() { return balance; } }

`package` is the first statement; the class is `public` (its published API) but the field is `private`, reached only through the public `getBalance()` accessor.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/61155635-6595-4905-a14e-b83eff83d95a/flashcard utf-8 LF