O'Reilly logo
  • Aadil Hussain thinks this is interesting:

Here’s an interesting situation: do you think a Book instance can access its private members using a reference variable?


Cover of OCA Java SE 8 Programmer I Certification Guide


No The following code won’t compile—even though variable b1 is of type Book, it’s trying to access its private method countPages outside Book: