3.11. Sample exam questions

Q3-1.

Which option defines a well-encapsulated class?

  1. class Template {
        public String font;
    }
  2. class Template2 {
        public String font;
        public void setFont(String font) {
            this.font = font;
        }
        public String getFont() {
            return font;
        }
    }
  3. 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;
        }
    }
  4. None of the above

Q3-2.

Examine the following code and select the correct option(s):

public class Person { public int height; public void setHeight(int newHeight) { if (newHeight <= 300) height = newHeight; ...

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.