~/ learn/ comp-308/ cards/ Access control & packages
1 of 5

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/27f5163f-390e-4c37-893d-a9e195435bba/flashcard utf-8 LF