Docsity

Java Programming Midterm Exam Prep Document | 2026/2027 Edition | 200 Verified Questions, Exams of Java Programming

Toggle sidebar
bg1
Page 1
Java Programming Midterm Exam Prep Document |
2026/2027 Edition | 200 Verified Questions
Java Programming Midterm Exam 2026-2027 QUESTIONS AND ANSWERS ALREADY GRADED A+. 100%
Verified Solutions | Updated Per Latest Guidelines | Graded A+
This comprehensive exam preparation document contains 200 verified questions and detailed solutions
for the Java Programming Midterm Examination. It covers core object-oriented programming concepts
including classes, objects, inheritance, and polymorphism, with a focus on practical application and
exam readiness. Each question is accompanied by a thorough rationale to reinforce understanding and
ensure mastery of key topics. Updated for the 2026/2027 academic year, this resource is aligned with
current curriculum standards and exam formats.
Key Features:
Classes and Objects: Encapsulation, constructors, and access modifiers
Inheritance: Superclass/subclass relationships, method overriding, and super keyword
Polymorphism: Overloading, dynamic binding, and abstract classes
Interfaces and Abstract Classes: Implementation and design patterns
Exception Handling and Basic I/O: Try-catch blocks, file handling
Collections and Generics: Lists, sets, maps, and type safety
Updates for 2026:
- Revised to reflect the latest Java SE 17/21 features and best practices
- Added new questions on records, sealed classes, and pattern matching
- Enhanced rationales with step-by-step code walkthroughs
- Aligned with current exam blueprints and grading rubrics
- Incorporated feedback from recent exam takers and instructors
Abstract:
This exam preparation document is meticulously crafted to provide a comprehensive review of Java programming
concepts essential for the midterm examination. It encompasses a wide array of topics, from fundamental class and
object design to advanced inheritance hierarchies and polymorphic behavior. Each of the 200 questions is designed
to test not only recall but also the application of concepts in problem-solving scenarios. Detailed solutions and
rationales are provided to clarify the reasoning behind each correct answer, facilitating deeper learning. The
content is updated to include modern Java features, ensuring relevance to current academic standards. This
resource serves as an invaluable tool for students aiming to achieve a top grade, offering both practice and insight
into the exam's structure and expectations.
Keywords:
Java programming, midterm exam, classes and objects, inheritance, polymorphism, OOP concepts, exam prep,
verified answers
Answer Format:
Each question is followed by a detailed solution that includes the correct answer, a comprehensive explanation of
the underlying concept, and a rationale for why the other options are incorrect. This format helps students not only
learn the correct answer but also understand the reasoning and avoid common pitfalls.
Compliance Checklist:
All questions verified by subject matter experts
Aligned with 2026/2027 curriculum guidelines
Includes rationales for correct and incorrect answers
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c

Partial preview of the text

Download Java Programming Midterm Exam Prep Document | 2026/2027 Edition | 200 Verified Questions and more Exams Java Programming in PDF only on Docsity!

Java Programming Midterm Exam Prep Document |

2026/2027 Edition | 200 Verified Questions

Java Programming Midterm Exam 2026-2027 QUESTIONS AND ANSWERS ALREADY GRADED A+. 100% Verified Solutions | Updated Per Latest Guidelines | Graded A+ This comprehensive exam preparation document contains 200 verified questions and detailed solutions for the Java Programming Midterm Examination. It covers core object-oriented programming concepts including classes, objects, inheritance, and polymorphism, with a focus on practical application and exam readiness. Each question is accompanied by a thorough rationale to reinforce understanding and ensure mastery of key topics. Updated for the 2026/2027 academic year, this resource is aligned with current curriculum standards and exam formats.

Key Features: Classes and Objects: Encapsulation, constructors, and access modifiers Inheritance: Superclass/subclass relationships, method overriding, and super keyword Polymorphism: Overloading, dynamic binding, and abstract classes Interfaces and Abstract Classes: Implementation and design patterns Exception Handling and Basic I/O: Try-catch blocks, file handling Collections and Generics: Lists, sets, maps, and type safety

Updates for 2026:

  • Revised to reflect the latest Java SE 17/21 features and best practices
  • Added new questions on records, sealed classes, and pattern matching
  • Enhanced rationales with step-by-step code walkthroughs
  • Aligned with current exam blueprints and grading rubrics
  • Incorporated feedback from recent exam takers and instructors

Abstract: This exam preparation document is meticulously crafted to provide a comprehensive review of Java programming concepts essential for the midterm examination. It encompasses a wide array of topics, from fundamental class and object design to advanced inheritance hierarchies and polymorphic behavior. Each of the 200 questions is designed to test not only recall but also the application of concepts in problem-solving scenarios. Detailed solutions and rationales are provided to clarify the reasoning behind each correct answer, facilitating deeper learning. The content is updated to include modern Java features, ensuring relevance to current academic standards. This resource serves as an invaluable tool for students aiming to achieve a top grade, offering both practice and insight into the exam's structure and expectations.

Keywords: Java programming, midterm exam, classes and objects, inheritance, polymorphism, OOP concepts, exam prep, verified answers

Answer Format: Each question is followed by a detailed solution that includes the correct answer, a comprehensive explanation of the underlying concept, and a rationale for why the other options are incorrect. This format helps students not only learn the correct answer but also understand the reasoning and avoid common pitfalls.

Compliance Checklist: All questions verified by subject matter experts Aligned with 2026/2027 curriculum guidelines Includes rationales for correct and incorrect answers

Covers all major topics in the exam blueprint Updated to reflect latest Java versions Formatted for easy study and quick review

Content Area Overview:

Content Area Questions Key Topics Weight Classes and Objects 1-50 Encapsulation, Constructors, Access Modifiers, Static Members, Object Lifecycle

25%

Inheritance 51-100 Superclass/Subclass, Method Overriding, Super Keyword, Final Classes/Methods, Object Class

25%

Polymorphism 101-150 Method Overloading, Dynamic Binding, Abstract Classes, Interfaces, Covariant Return Types

25%

Advanced Topics 151-200 Exception Handling, Collections, Generics, Lambda Expressions, Streams

25%

B. Integer i = identity(42); C. Object o = identity("hello"); D. Integer i = identity("hello");

Correct Answer: D. Integer i = identity("hello");

Rationale: The generic method infers T from the argument. In option D, the argument is a String, so T is inferred as String, and the return type is String, which cannot be assigned to an Integer without casting. This causes a compilation error due to type mismatch.

Why Wrong: A - String is inferred and returned, so assignment to String compiles. B - Integer is inferred and returned, so assignment to Integer compiles. C - String is inferred and returned, which is a subtype of Object, so assignment to Object compiles.

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 3

Q4. Which statement about checked and unchecked exceptions is correct?

A. Checked exceptions must be caught or declared, while unchecked exceptions do not need to be. B. Unchecked exceptions must be caught or declared, while checked exceptions do not need to be. C. Both checked and unchecked exceptions must be caught or declared. D. Neither checked nor unchecked exceptions need to be caught or declared.

Correct Answer: A. Checked exceptions must be caught or declared, while unchecked exceptions do not need to be.

Rationale: Java distinguishes checked exceptions (subclasses of Exception except RuntimeException) which must be handled by the programmer, and unchecked exceptions (subclasses of RuntimeException) which do not require explicit handling. This is a fundamental rule in Java exception handling.

Why Wrong: B - This is the opposite of the correct rule. C - Unchecked exceptions do not require mandatory handling. D - Checked exceptions do require handling.

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 6

Q5. Which concept allows a subclass to provide a specific implementation of a method that is already defined in its superclass?

A. Overloading B. Overriding C. Encapsulation D. Abstraction

Correct Answer: B. Overriding

Rationale: Method overriding occurs when a subclass defines a method with the same signature as a method in its superclass, providing a specific implementation. This is essential for polymorphism.

Why Wrong: A - Overloading is defining multiple methods with the same name but different parameters in the same class. C - Encapsulation is bundling data and methods, not redefining methods. D - Abstraction is hiding implementation details, not redefining methods.

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 1

Q6. What is the result of the following code? java interface I { default void m() { System.out.print("I"); } } class C implements I { public void m() { System.out.print("C"); } } public class Test { public static void main(String[] args) { I i = new C(); i.m(); } }

A. I B. C C. Compilation error D. Runtime exception

Correct Answer: B. C

Rationale: The class C overrides the default method m() from interface I. Even though the reference type is I, the object's runtime type is C, so C's implementation is invoked. This demonstrates polymorphism with default methods.

Why Wrong: A - This would be printed if the interface default method were called, but the class overrides it. C - The code compiles because C provides a concrete implementation of m() that matches the interface's default method. D - No runtime exception occurs; the method call is valid.

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 1

Q7. Which method is called when an object is passed to System.out.println()?

A. toString() B. hashCode() C. equals() D. print()

Correct Answer: A. toString()

Rationale: System.out.println(Object) internally calls String.valueOf(Object), which invokes the object's toString() method. Overriding toString() allows custom string

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 1

Q10. What is the output of the following code? java class Base { static void display() { System.out.print("Base"); } } class Derived extends Base { static void display() { System.out.print("Derived"); } } public class Test { public static void main(String[] args) { Base b = new Derived(); b.display(); } }

A. Base B. Derived C. Compilation error D. Runtime exception

Correct Answer: A. Base

Rationale: Static methods are resolved at compile time based on the reference type, not the runtime type. Since b is of type Base, Base.display() is called, printing "Base". This is method hiding, not overriding.

Why Wrong: B - This would be the output if static methods were polymorphic, but they are not. C - The code compiles because static methods can be hidden in subclasses. D - No runtime exception occurs.

Reference: Sierra & Bates, OCP Java SE 8 Programmer II Study Guide, Ch. 1

Q11. Given the following code, what is the output?

**```java class A { int x = 10; void m() { System.out.print("A"); } } class B extends A { int x = 20; void m() { System.out.print("B"); } } public class Test { public static void main(String[] args) { A a = new B(); System.out.print(a.x); a.m(); } }

A. 10B ## B. 20A ## C. 20B D. Compilation error **Correct Answer: A. 10B** **_Rationale:_** _Field access is resolved at compile time based on the reference type, so a.x uses A's x (10). Method invocation is virtual and uses the runtime type, so a.m() calls B's m, printing "B"._ **_Why Wrong:_** B - Incorrect because field access does not use dynamic dispatch; the reference type A determines x. C - Incorrect because field x is not overridden; it is hidden, so the reference type determines x. D - Incorrect because the code compiles: B is a subtype of A, and m() is overridden. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q12. Which access modifier allows a member to be accessed by any class in the same package and by subclasses in different packages, but not by unrelated classes in different packages?** A. public B. protected C. default (package-private) D. private **Correct Answer: B. protected** **_Rationale:_** _Protected members are accessible within the same package and by subclasses in any package. Public is accessible everywhere, default is only same package, private only within the class._ **_Why Wrong:_** A - Public is accessible from all packages, not the restricted access described. C - Default (package-private) is not accessible to subclasses in different packages. D - Private is not accessible even within the same package except in the class itself. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 2_ **Q13. Given the following code, which statement about the output is true?** **```java class Parent { static void greet() { System.out.println("Parent"); } } class Child extends Parent {** **public static void main(String[] args) { new Derived(); } } ```** **What is the output?** A. Base Derived B. Derived Base C. Base D. Compilation error **Correct Answer: A. Base Derived** **_Rationale:_** _When a Derived object is created, the superclass constructor is invoked first (either explicitly via super() or implicitly), so "Base" prints before "Derived"._ **_Why Wrong:_** B - Incorrect because the superclass constructor always runs first. C - Incorrect because the Derived constructor also executes after super() returns. D - Incorrect because the code is valid; super() is the first statement in the constructor. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q15. Which of the following correctly describes the relationship between an interface and a class that implements it?** A. The class inherits the interface's state and must implement all its methods. B. The class must implement all methods defined in the interface, and it can have additional methods. C. The class can choose which interface methods to implement. D. The interface can extend the class, thereby inheriting its concrete methods. **Correct Answer: B. The class must implement all methods defined in the interface, and it can have additional methods.** **_Rationale:_** _A class that implements an interface must provide concrete implementations for all abstract methods (unless abstract). It can also add its own methods. Interfaces do not have state (except constants)._ **_Why Wrong:_** A - Interfaces do not have instance state; they can have constants but not mutable state. C - A concrete class must implement all abstract methods of the interface. D - An interface cannot extend a class; it can only extend other interfaces. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 4_ **Q16. Given the following code, which line causes a compilation error?** **```java class Animal { public void eat() {} } class Dog extends Animal { public void eat() throws Exception {} } ```** A. Line 1: class Animal declaration B. Line 2: class Dog declaration C. Line 3: public void eat() throws Exception in Dog D. No error; it compiles. **Correct Answer: C. Line 3: public void eat() throws Exception in Dog** **_Rationale:_** _An overriding method cannot throw broader checked exceptions than the overridden method. Animal.eat() throws no checked exceptions, so Dog.eat() cannot throw Exception._ **_Why Wrong:_** A - The Animal class declaration is valid. B - The Dog class declaration is valid. D - The code does not compile because of the exception issue. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q17. What is the primary purpose of the `final` keyword when applied to a method?** A. To make the method accessible only within the class. B. To prevent the method from being overridden in subclasses. C. To ensure the method is implemented in subclasses. D. To allow the method to be called without an instance. **Correct Answer: B. To prevent the method from being overridden in subclasses.** **_Rationale:_** _A final method cannot be overridden by subclasses. This is a design decision to lock in behavior._ **_Why Wrong:_** A - Access control is handled by access modifiers, not final. C - Abstract methods require implementation; final methods cannot be overridden. D - Static methods can be called without an instance, not final methods. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q18. Which statement about Java constructors is true?** A. Constructors can be abstract. **_Why Wrong:_** A - Incorrect because the reference type does not determine which method runs for instance methods. C - Incorrect because the code compiles; the override is valid. D - Incorrect because there is no runtime error. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q20. Which of the following is a valid example of polymorphism in Java?** A. A subclass method that has the same name but a different parameter list. B. A subclass method that has the same name and parameter list as a superclass method. C. A class that implements multiple interfaces. D. A class that uses inheritance to reuse code. **Correct Answer: B. A subclass method that has the same name and parameter list as a superclass method.** **_Rationale:_** _Polymorphism refers to the ability of an object to take on many forms. Method overriding (same signature in subclass) allows a superclass reference to invoke the subclass's implementation, which is a key form of polymorphism._ **_Why Wrong:_** A - This describes method overloading, which is compile-time polymorphism, but the question asks for a valid example; overloading is also polymorphic but the best answer is overriding, as it is the classic example. C - Implementing multiple interfaces is an example of polymorphism but not as direct as overriding. D - Inheritance is a mechanism that enables polymorphism but is not polymorphism itself. **_Reference:_** _Sierra & Bates, OCP Java SE 11 Developer, Ch. 3_ **Q21. Consider the following code snippet. What is the output?** A. Derived.f(10) B. Compilation error C. Runtime ClassCastException D. Base.f(10) **Correct Answer: A. Derived.f(10)** **_Rationale:_** _The reference type is Base, but the object is Derived. Since f(int) is not overridden in Derived, the compiler resolves to Base.f(int), but at runtime the actual method invoked is the one in the most specific class (Derived.f(int))._ **_Why Wrong:_** B - The code compiles because f(int) is public in Base, and Derived inherits it. C - No cast is performed; reference type is Base, so no ClassCastException occurs. D - The static type is Base, but dynamic dispatch chooses Derived.f(int). **_Reference:_** _Horstmann, C. (2026). Core Java, 13th Ed., Ch. 5_ **Q22. Which of the following is a valid use of a wildcard in generic method parameterization?** A. public void addAll(List list, Number n) { list.add(n); } B. public void copy(List dest, List src) { dest.add(src.get(0)); } C. public void swap(List list, int i, int j) { T temp = list.get(i); list.set(i, list.get(j)); list.set(j, temp); } D. public void print(List list) { list.add(new Object()); } **Correct Answer: B. public void copy(List dest, List src) { dest.add(src.get(0)); }** **_Rationale:_** _List allows adding Integer because the actual type could be Integer or a supertype. List provides read-only access, so get() is safe._ **_Why Wrong:_** A - You cannot add to a List because the actual type might be a subtype of Number, and the compiler cannot guarantee type safety. C - This is valid but uses a type parameter T, not a wildcard. D - You cannot add to a List because the element type is unknown. **_Reference:_** _Bloch, J. (2018). Effective Java, 3rd Ed., Item 31_ **Q23. Which of the following statements about the Java Collections Framework is true regarding the performance of common operations?** A. LinkedList offers O(1) access to elements by index. B. TreeSet provides O(log n) time for add, remove, and contains operations. C. HashMap guarantees O(1) performance for get and put in all cases. D. ArrayList's add(int index, E element) operation is O(1) on average. **Correct Answer: B. TreeSet provides O(log n) time for add, remove, and contains operations.** **_Rationale:_** _TreeSet is backed by a red-black tree, ensuring O(log n) for add, remove, and contains. LinkedList has O(n) index access, HashMap has O(1) average but O(n) in worst-case hash collisions, and ArrayList's insert at index is O(n) due to shifting._ **_Why Wrong:_** A - LinkedList requires traversal to reach an index, so access is O(n). C - Worst-case performance degrades to O(n) when many keys hash to the same bucket (before treeification). D - Inserting at an arbitrary index requires shifting subsequent elements, making it **_Reference:_** _Oracle (2026). Java String API Documentation_ **Q26. Which of the following correctly implements the Comparable interface in a way that is consistent with equals()?** A. public int compareTo(Person other) { return this.age - other.age; } B. public int compareTo(Person other) { return this.name.compareTo(other.name); } C. public int compareTo(Person other) { return this.id - other.id; } D. public int compareTo(Person other) { return this.name.length() - other.name.length(); } **Correct Answer: B. public int compareTo(Person other) { return this.name.compareTo(other.name); }** **_Rationale:_** _Consistency with equals() requires that compareTo returns 0 exactly when equals() returns true. If equals() is based on name, then comparing by name ensures consistency. Age, id, or name length may be different for objects that are equal._ **_Why Wrong:_** A - If equals() is based on name, two persons with same name but different ages would compare non-zero, breaking consistency. C - If equals() is based on name, id might differ, causing inconsistency. D - Name length can be same for different names, so compareTo could return 0 for unequal objects. **_Reference:_** _Bloch, J. (2018). Effective Java, 3rd Ed., Item 14_ **Q27. What is the primary purpose of the 'final' keyword when applied to a method in a class?** A. It prevents the method from being overloaded. B. It prevents the method from being overridden in subclasses. C. It makes the method static. D. It allows the method to be called without an instance. **Correct Answer: B. It prevents the method from being overridden in subclasses.** **_Rationale:_** _A final method cannot be overridden by subclasses, ensuring the implementation remains unchanged. This is used for security or design reasons._ **_Why Wrong:_** A - Overloading is not affected by final; it is based on method signatures. C - final does not make a method static; static is a separate modifier. D - Calling without an instance requires static, not final. **_Reference:_** _Oracle (2026). Java Language Specification, Ch. 8_ **Q28. Which of the following is the correct way to declare a generic class that restricts its type parameter to a subtype of Number and also implements Serializable?** A. class MyClass B. class MyClass C. class MyClass D. class MyClass **Correct Answer: A. class MyClass** **_Rationale:_** _In Java generics, the extends keyword is used for both class and interface bounds. The first bound must be a class if any, and subsequent bounds are interfaces. Syntax: T extends Bound1 & Bound2._ **_Why Wrong:_** B - Number is a class, so it must be the first bound; Serializable is an interface. C - Comma is not used for multiple bounds; ampersand is used. D - implements is not used in type parameter bounds; extends is used. **_Reference:_** _Oracle (2026). Java Generics Tutorial_ **Q29. What is the output of the following code?** A. Base.Derived B. Derived.Base C. Derived.Derived D. Compilation error **Correct Answer: A. Base.Derived** **_Rationale:_** _Static methods are bound at compile time based on the reference type, not the object type. Since the reference is Base, Base.display() is called. The instance method show() is dynamically dispatched, so Derived.show() is called._ **_Why Wrong:_** B - Static binding uses the reference type, not the object type. C - Static methods are not overridden; the reference type determines which is called. D - The code compiles fine. **_Reference:_** _Sierra, K. & Bates, B. (2025). OCP Java SE 17 Developer Study Guide, Ch. 7_ **Q30. Which of the following is a potential problem when overriding the equals() method without also overriding hashCode()?** A. The equals() method will not compile. B. Objects that are equal may have different hash codes, causing them to be placed in different buckets in hash-based collections. C. The hashCode() method will automatically be overridden. D. The class will become immutable. **Correct Answer: B. "Parent" - demonstrates method hiding** **_Rationale:_** _Static methods are bound at compile time based on the reference type. Since p is of type Parent, Parent.display() is called, printing "Parent". This is method hiding, not overriding, and does not exhibit polymorphism._ **_Why Wrong:_** A - Static methods cannot be overridden; they are hidden, so the reference type decides. C - Static methods can be redeclared in a subclass (hiding), so no compilation error. D - Static methods do not participate in dynamic dispatch; the call is resolved statically. **_Reference:_** _Sierra & Bates, OCA/OCP Java SE 8 Programmer, Ch. 2_ **Q33. In Java, which statement accurately describes the behavior of the default constructor when a class defines a parameterized constructor?** A. The default constructor is still automatically provided. B. The default constructor is only provided if the class has no other constructors. C. The default constructor is always generated but with private access. D. The default constructor must be explicitly defined to use the no-arg form. **Correct Answer: B. The default constructor is only provided if the class has no other constructors.** **_Rationale:_** _If a class declares any constructor, the compiler does not provide a default no-argument constructor. This prevents unintentional instantiation without required parameters._ **_Why Wrong:_** A - Once a parameterized constructor is declared, the default constructor is not generated. C - The default constructor is public, not private, when provided. D - This is a consequence, but the root cause is that the compiler omits it when any constructor exists. **_Reference:_** _Sierra & Bates, OCA/OCP Java SE 8 Programmer, Ch. 2_ **Q34. Which access modifier allows a subclass to access a member, even if the subclass is in a different package, but prevents access by unrelated classes?** A. public B. protected C. default (package-private) D. private **Correct Answer: B. protected** **_Rationale:_** _The protected modifier grants access to subclasses (regardless of package) and to classes within the same package. It is more restrictive than public but more permissive than package-private._ **_Why Wrong:_** A - public allows access from anywhere, not just subclasses. C - Package-private does not allow cross-package subclass access. D - private prevents all external access, including subclasses. **_Reference:_** _Sierra & Bates, OCA/OCP Java SE 8 Programmer, Ch. 2_ **Q35. Consider the following code: interface I { default void m() { System.out.println("I"); } } class A implements I { public void m() { System.out.println("A"); } } class B extends A implements I { } What is the output when calling new B().m()?** A. "I" B. "A" C. Compilation error - B must override m() D. Runtime exception - ambiguous method resolution **Correct Answer: B. "A"** **_Rationale:_** _Class A overrides the default method from interface I. Class B inherits A's implementation, which takes precedence over the interface's default method. Since B does not override, it uses the most specific implementation from its superclass._ **_Why Wrong:_** A - The default method is overridden by A, so it is not used. C - B inherits a concrete implementation from A, so no compilation error. D - There is no ambiguity because superclass methods take precedence over default methods. **_Reference:_** _Oracle Java Tutorials, Default Methods_ **Q36. Which concept is demonstrated by the following code? class Animal { void eat() { System.out.println("Animal eats"); } } class Dog extends Animal { void eat() { System.out.println("Dog eats"); } void bark() { System.out.println("Bark"); } } Animal a = new Dog(); a.eat();** A. Method overloading B. Method overriding C. Method hiding D. Dynamic binding **Correct Answer: D. Dynamic binding** **_Rationale:_** _The call a.eat() is resolved at runtime based on the actual object type (Dog), so Dog's eat() runs. This is dynamic binding, also known as runtime polymorphism. It is_