7 Enthuware questions, 7 misses. Below are the rules behind each one, then original drills written to hit the same rules from new angles. Every code sample was compiled and run on JDK 21.
{ }, and abstract/native methods aren't.private final fields plus a public accessor x() (not getX()). Outside the record, use r.x(), never r.x.public, return exactly the component type, and have no throws (not even for unchecked exceptions).String name().id = id + 1), but this.x = … isn't, because the compiler assigns the fields after your last line.throws, not generic, and at least as accessible as the record.this(…), and throws is allowed. The canonical constructor is still generated if you don't write one.extends (the superclass is always java.lang.Record), implicitly final, implements any number of interfaces. A record can't be abstract, sealed or non-sealed.static. static is allowed on a member record but not on a local one, and a local record can't use the method's local variables.clone, finalize, getClass, hashCode, notify, notifyAll, toString or wait.equals/hashCode/toString read the fields directly, not your accessors. Array components are compared by reference.o instanceof P(int a, var b): one nested pattern per component, matched by position. You can choose any names.var is allowed for components but not for the outer type (o instanceof var p doesn't compile).Box(var s) infers the type arguments. Box<String>(String s) is fine too. No diamond Box<>(…).int component can't be matched with long v.&& and in the true branch, but not after ||. if (!(o instanceof P(…))) return; puts them in scope afterwards.sealed + final is a compile error. A sealed class must have at least one subclass.final, sealed or non-sealed. Records are implicitly final, so they qualify.permits, the subclasses are inferred from the same source file.switch over a sealed type covering every subtype needs no default.int rank; in a record bodyA record body can't declare instance fields. The only fix among the options was making it static. Making it private or giving it a value doesn't help.
Any number. There's exactly one canonical constructor (compact or normal form) plus any number of overloads that start with this(…).
A record can't use extends and can't be extended, but it can implement any number of interfaces. It can hold other records, and it can be Serializable (deserialization goes through the canonical constructor).
A sealed interface permitting a record, a redundant final, a stray ;, a method with a parameter, a method called setRole that assigns nothing, and nested var patterns: all legal. The generated accessor role() implements the interface's String role().
Relation(var a, var b) on a Relation<Student, Course>Type arguments are inferred, so you don't need <> and it isn't allowed. a.name fails because the field is private (use a.name()). Pattern variables are out of scope after ||.
||, the pattern variables are gone.Concrete and nested classes can be sealed. Records and enums can't, but both can implement a sealed interface.
final means no subclasses, sealed means only the listed ones, so you can't have both.Journal { id = id + 1; } plus a normal Journal(int id, String name)That's a duplicate canonical constructor. Removing the normal one fixes it, and the compact constructor's id = id + 1 changes the parameter, which then becomes the field's value.
this.x. In a normal one, you must write every this.x.Work through blocks 1–7, then sit the timed mock. Reload the page to reshuffle. Aim for full marks on each block before you try the mock.
| Drill block | Qs | Last | Best | Runs | Last done |
|---|---|---|---|---|---|
| Loading… | |||||
Each statement on its own. This is the "give each option a yes or no" habit.
25 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 60 minutes, roughly the real exam's pace, and the pass mark is 68%.