3.12. Answers to sample exam questions
Which option defines a well-encapsulated class?
class Template { public String font; } class Template2 { public String font; public void setFont(String font) { this.font = font; } public String getFont() { return font; } } class Template3 { private String font; public String author; public void setFont(String font) { this.font = font; } public String getFont() { return font; } public void setAuthor(String author) { this.author = author; } public String getAuthor() { return author; } }- None of the above
Answer: d
Explanation: Options (a), (b), and (c) are incorrect because they all define a public instance variable. A well-encapsulated class should be like a capsule, hiding its ...
Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.