Test 14 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Interfaces have moved on a long way from just being a list of methods and this free 1Z0-831 mock exam covers all the modern interface capabilities. The questions cover abstract methods, default methods, static methods, private methods, constants, inheritance conflicts and functional interfaces. All of these appear in a number of the objectives for the Java SE 25 Developer certification.
You start with the basic rules. Interface methods are implicitly public and abstract unless otherwise stated, fields are implicitly public, static and final and a class which implements an interface must provide all of the abstract methods or be abstract itself. There's a test of what happens when you weaken the access in an implementing method (a compile error which is very easy to miss).
Default methods are the source of the most interesting puzzles. You'll be looking at the classic diamond problem where a class inherits two default methods with the exact same signature. The compiler will require that the class overrides the method and you can choose which of the parent versions to use via InterfaceName.super.method(). There are also questions around the fact that a class method always wins over an interface default and that a more specific interface will override a less specific one.
Static and private interface methods each get their own set. Static methods are part of the interface and aren't inherited so they have to be called via the interface name. Private methods allow default methods to share some helper code without making that code public. You'll be able to predict which of the calls will compile and which will be rejected.
Functional interfaces make up the second half. An interface with precisely one abstract method is a functional interface (it may contain default methods or re-declare public methods from Object). You'll need to be able to determine whether an interface is functional, use the @FunctionalInterface annotation appropriately and be familiar with the standard java.util.function types: Predicate, Function, Supplier, Consumer, UnaryOperator and BinaryOperator (and their primitive variants).
Lambda and method reference questions relate to these types and you have to work out which target type the given expression is. The explanations will always name the applicable rule. The questions can occasionally be a bit more complex in that they'll involve an interface which extends two others which have conflicting defaults. It's a good idea to draw out the hierarchy on paper and then work through each call from the most specific type up as that process eliminates almost all of the confusion. Do the test, go through and mark every answer you guessed and then go back and relearn those rules until you can state them without any hesitation.
