← All topics · Attempt 1 page

Java 21 OCP · Objective: Records and Sealed classes · Attempt 2

Records & Sealed Classes: second go

I retook the 8-question Enthuware test on 2 Nov 2026. Three of my attempt 1 misses are now fixed and three new rules caught me out. This page drills only those three rules, with new original questions. Every code sample was compiled and run on JDK 21.

Attempt 2 scorecard

#Rule testedResultvs attempt 1
1A permitted subtype must itself extend or implement the sealed type✗New miss → block 1
2Generic record patterns, no diamond, flow scope after ||✓Fixed
3Members a record gets automatically✓New, right first time
4"Sealed" doesn't mean "can't be extended"; what can be sealed✗Repeat weak spot → block 2
5Records are final, nested records are static, and immutability is shallow✗New miss → block 3
6Compact plus normal canonical constructor is a duplicate✓Fixed
7not recorded yet–
8A record can have any number of overloaded constructors✓Fixed

Recorded so far: 4 / 7. All three misses are about what the modifiers sealed, non-sealed and final actually mean, and records are part of that.

The three rules

1 · A sealed relationship is declared on both sides
2 · Sealed means "restricted", not "closed"
3 · What a record is implicitly

What I got wrong this time

Attempt 2 · Q1 · Permits clause

A permitted class that never said implements

I thought being listed in permits made the class a subtype. It doesn't, so non-sealed class Result { } failed twice: the parent's permits clause was invalid, and non-sealed had no sealed parent to reopen.

Hook: the parent permits it, and the child must still implements/extends the parent.
Attempt 2 · Q4 · What sealed means

"A sealed class cannot be extended" sounded true

It's false. A sealed class must be extended, but only by the types it permits. The answer was "none of the above", because the other options were also false: interfaces can be sealed, and records and enums can't be.

Hook: final = nobody · sealed = only the listed types · non-sealed = anyone again.
Attempt 2 · Q5 · Record properties

Which three things are records implicitly?

Final, static when nested, and immutable (shallowly). They're not sealed, because a final type has no subtypes. They're also not about limiting the number of instances.

Hook: records are Final, Static when nested, and Shallow: "FSS", never sealed.
Fixed since attempt 1

Generic record patterns · duplicate canonical constructors · any number of overloads

All three were right this time. They're still covered by blocks 2 and 5 on the attempt 1 page.

My drill progress on this page

Work through blocks 1–4, then sit the timed mock. Reload the page to reshuffle. Aim for full marks on each block before you try the mock.

Drill blockQsLastBestRunsLast done
Loading…

1 · Both sides of permits Q1

2 · What sealed really means Q4

3 · Implicit record properties Q5

4 · True or false (quick-fire)

Each statement on its own. This is the "give each option a yes or no" habit, which would have saved Q4 and Q5.

Timed mock

20 questions drawn at random from all the blocks above, with fresh question and option order every time. There's no feedback until you submit. You get 40 minutes, and the pass mark is 68%.

← All topics · Attempt 1 page