Overriding Interface Default Methods | Oracle Certified Professional Java SE 17 Explained
This 1Z0-829 practice question tests your understanding of utilizing java object-oriented approach. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
// File: com/example/MyInterface.java
public interface MyInterface {
default void show() {
System.out.println("Interface default");
}
}
// File: com/example/MyClass.java
public class MyClass implements MyInterface {
public void show() {
System.out.println("Class implementation");
}
}
// File: com/example/Test.java
public class Test {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.show();
}
}
Refer to the exhibit. What is the output?
Exhibit
// File: com/example/MyInterface.java
public interface MyInterface {
default void show() {
System.out.println("Interface default");
}
}
// File: com/example/MyClass.java
public class MyClass implements MyInterface {
public void show() {
System.out.println("Class implementation");
}
}
// File: com/example/Test.java
public class Test {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.show();
}
}
A
Class implementation
The overridden method in MyClass is called, not the default method from the interface.
B
Runtime exception due to conflicting methods.
Why wrong: No conflict; the class method takes precedence.
C
Compilation error because show() is default in interface and cannot be overridden.
Why wrong: Default methods can be overridden.
D
Interface default
Why wrong: The implementation in MyClass overrides the default.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Class implementation
Option A is correct because when a class implements an interface that provides a default method, the class can override that default method with its own implementation. In this case, the class provides a concrete implementation of the `show()` method, which takes precedence over the interface's default method. Therefore, the output is 'Class implementation'.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✓
Class implementation
Why this is correct
The overridden method in MyClass is called, not the default method from the interface.
Related concept
Read the scenario before looking for a memorised answer.
✗
Runtime exception due to conflicting methods.
Why it's wrong here
No conflict; the class method takes precedence.
✗
Compilation error because show() is default in interface and cannot be overridden.
Why it's wrong here
Default methods can be overridden.
✗
Interface default
Why it's wrong here
The implementation in MyClass overrides the default.
Common exam traps
Common exam trap: answer the scenario, not the keyword
The trap here is that candidates may think default methods in interfaces cannot be overridden, confusing them with static methods or final methods, or they may incorrectly assume that a conflict between a default method and a class method causes a runtime exception.
Detailed technical explanation
How to think about this question
In Java, default methods in interfaces were introduced in Java 8 to allow interfaces to have method bodies without breaking existing implementations. When a class overrides a default method, the class's implementation is used, and the interface's default is effectively hidden. This is similar to how a superclass's method is overridden by a subclass, but with the distinction that default methods are not inherited from a superclass but from an interface. A real-world scenario is when you have a library interface with a default method, and a client class provides a more specific implementation to optimize performance or add logging.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the 1Z0-829 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Utilizing Java Object-Oriented Approach — This question tests Utilizing Java Object-Oriented Approach — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: Class implementation — Option A is correct because when a class implements an interface that provides a default method, the class can override that default method with its own implementation. In this case, the class provides a concrete implementation of the `show()` method, which takes precedence over the interface's default method. Therefore, the output is 'Class implementation'.
What should I do if I get this 1Z0-829 question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
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 →
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.
This 1Z0-829 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-829 exam.
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.
Sign in to join the discussion.