Courseiva
Question 248 of 481
Object-Oriented ProgrammingeasyMultiple ChoiceObjective-mapped

1Z0-811 Object-Oriented Programming Practice Question

A company develops a payroll system in Java with a hierarchy: Employee, Manager (extends Employee), and Director (extends Manager). Each class overrides a method getDetails() that returns a string with employee information. Employee's getDetails() returns name and ID. Manager's getDetails() adds department. Director's getDetails() adds division. The system uses a single method printDetails(Employee e) that calls e.getDetails(). After a recent deployment, the system prints only the name and ID for all employees, even for managers and directors. The code review reveals that Employee's getDetails() is declared with default (package-private) access, while the overridden versions in Manager and Director are public. The printDetails method and the Manager/Director classes are in different packages. What is the most likely cause and the correct solution?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Change the access modifier of getDetails() in Employee to public (or protected).

In Java, a default-access method is not visible to subclasses in different packages, so Manager and Director cannot override it; their getDetails() methods are new methods, not overriding Employee's. Making Employee's getDetails() public (or protected) allows proper overriding and polymorphic behavior. Option B is wrong because it bypasses polymorphism. Option C is wrong because @Override only helps catch errors, but the access issue remains. Option D is wrong because making the method final would prevent overriding entirely.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Change the access modifier of getDetails() in Employee to public (or protected).

    Why this is correct

    A is correct: default access prevents overriding from different packages; changing to public enables proper polymorphism.

  • Modify printDetails() to accept Manager or Director objects instead of Employee.

    Why it's wrong here

    B is wrong: this breaks polymorphism and requires overloaded methods.

  • Add @Override annotation to the overridden methods in Manager and Director.

    Why it's wrong here

    C is wrong: @Override only catches mistakes at compile time; it does not fix the access issue.

  • Declare getDetails() in Employee as final to ensure consistent behavior.

    Why it's wrong here

    D is wrong: final prevents overriding, which is the opposite of the desired fix.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 23, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.