~/ 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/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF