banner Test 12

Test 12 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional

Inheritance questions are all about careful reading and this free Java SE 25 1Z0-831 mock test is a great way to get some practice. It's all about class hierarchies, abstract classes, sealed types, polymorphism and the difference between an object's type and its reference type (that distinction is what determines a huge number of the object oriented questions).

You start off with the basics of extending a class. The questions are: which members does a subclass inherit? How does super get to the parent's version of a method? Why are constructors never inherited? Abstract classes are tested via snippets that attempt to instantiate them, omit an implementation, or mix abstract with final or private (which is illegal).

Overrides come next. A valid override has the same signature, a compatible or covariant return type, equal or wider access and throws no broader checked exceptions. Static methods and fields are hidden rather than overridden so calls are resolved by reference type (a trap that crops up again and again). You'll also see how @Override can help the compiler catch your typing errors.

Sealed types are a real highlight. A sealed class or interface uses permits to name its direct subtypes and each permitted subtype must be final, sealed or non-sealed. You'll be determining whether a hierarchy will compile (what the permitted classes are when there's no permits clause), what the permitted classes are in the case of a sealed hierarchy and how sealed hierarchies can be used to enable exhaustive switch expressions without a default case. Records and enums as permitted subtypes are also supported.

Polymorphism is the bit that brings it all together. You'll be looking at when a parent reference will invoke which method (i.e. which method will be called when a parent reference points to a child object), you'll be looking at when a cast will compile and when it will throw ClassCastException at runtime, and you'll be using instanceof pattern matching to safely narrow types. There will be questions on field access via references (the field accessed is determined by the declared type of the reference, not the type of the object). Interfaces come into it too, as a class can implement several interfaces but can only extend one parent class. You'll be looking at class diagrams, eliminating the illegal combinations and spotting where an inherited default or abstract method could be in conflict.

Every explanation draws a clear line between compile time reasoning and runtime behaviour which is absolutely the single most important thing to get into your head for this topic. Do the test, note every instance where the two have got confused and go back and re-examine those before you go and do the next mock.

Welcome to your Free Java SE 25 – Test 12