OCP Question 13, Explanation

Given:

public final class WordPress {
    public void login() {}
}piblic class Post {
    public final void write(int words, int pix) {}
    public void uploadMedia() {}
}
piblic class FrontPage {
    private Post p = new Post();
    private final String subj = "OCA & OCP Prep Tools";
    public void compose(){ p.write(1200, 2); }
}
piblic class StickyPost extends Post {
    public void write(int numberOfWords, int numberOfPix) {}
    public void publish() {}
}

 

Which statement is true?

A. A compilation error occurs in WordPress.
B. A compilation error occurs in Post.
C. A compilation error occurs in FrontPage.
D. A compilation error occurs in StickyPost.
E. All classes compile successfully.

The correct answer is D.

The write() method in Post is final and cannot be overridden.

Leave Comment

Your email address will not be published.