Test7 banner

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

Objects are the heart of Java and this free Java SE 25 mock test for the 1Z0-831 certification is all about objects. It looks at how objects are declared, instantiated and eventually garbage collected. The topics covered are classes, instance and static members, nested types and the object lifecycle. All of this is obviously part of the wider OOP agenda that the Oracle exam is all about.

You start with instantiation. The questions will be all over the place as to which constructor gets called, in what order the fields get initialised and what a reference variable actually ends up holding after an assignment. There will be a number of items that compare instance and static members and you need to know that static fields are shared by all objects whereas instance fields are specific to each object. You'll see snippets where a static method is called via an object reference and where an instance field is accessed from a static context and you need to know which one will actually compile.

Nested classes get a good deal of coverage. You'll be looking at static nested classes, inner classes, local classes and anonymous classes and working out how each of them is created. An inner class requires an enclosing instance so you'll see a statement of the form outer.new Inner() appearing more than once. You'll also be looking at which local variables a nested class can capture, which must be final or effectively final and why reassignment of one of those later will result in a compilation error.

The lifecycle section looks at reference behaviour. You'll be looking at code where a reference is set to null, reassigned to another object or passed into a method which then reassigns its own copy of the parameter. Java passes references by value and these questions prove that. The GC questions ask when an object is eligible for collection rather than when it is actually collected (the exam will never let you assume a collection will occur). Islands of isolation (two objects referencing each other only) are also included.

Initialisation order is worth its own section really. Static blocks execute once when the class loads. Instance blocks execute prior to each constructor body. Field initialisers execute in the order they appear in the code. The explanations will tell you the exact order so you can replicate it on the day of the exam. Be aware that exam questions will often have one extra line slipped in somewhere (e.g. a static counter being incremented inside a constructor) so you need to be very careful to look at the whole class before you make your decision.

Take the test, go through each trace and rewrite the tricky bits yourself until the order of them all feels natural.

Welcome to your Free Java SE 25 – Test 7