Category: Oracle Certification Exam
-
Constants in Interfaces – Object-Oriented Programming
Constants in Interfaces A field declaration in an interface defines a named constant. Naming conventions recommend using uppercase letters, with multiple words in the name being separated by underscores. Such constants are considered to be public, static, and final. These modifiers are usually omitted from the declaration, but can be specified in any order. Such…
-
Compact Canonical Record Constructor – Object-Oriented Programming
Compact Canonical Record Constructor The compact canonical record constructor is a more concise form of the normal canonical record constructor. It eliminates the need for a parameter list and the initialization of the component fields. The parameter list is derived from the component list declared in the record header, and the initialization of all component…
-
Normal Non-Canonical Record Constructors – Object-Oriented Programming
Normal Non-Canonical Record Constructors A record class declaration can specify any number of non-canonical record constructors—that is, constructors whose signature is not the same as that of the canonical constructor. In Example 5.30, a non-canonical constructor for the record class CD is implemented at (5). It is a zero-argument non-canonical record constructor to create a…
-
Member Declarations – Object-Oriented Programming
Member Declarations The component fields of a record class are always automatically generated based on the field components specified in the component list. Thus a record class cannot declare any new instance fields in addition to those specified in the component list. However, new instance methods can be declared in a record class. In Example…
-
Other Aspects of Record Classes – Object-Oriented Programming
Other Aspects of Record Classes Some other aspects of record classes are mentioned below, and are covered in detail elsewhere in the book. Implementing Interfaces Records can implement interfaces, which is no different from a normal class implementing interfaces. As a record class is implicitly final, it cannot extend other classes. The CD record class…
-
Sealed Classes and Interfaces – Object-Oriented Programming
5.15 Sealed Classes and Interfaces Design by inheritance promotes code reuse in the OOP model—where subtypes can inherit code from their supertypes. Such an inheritance hierarchy is depicted in Figure 5.8, where the subclasses PrintedBook, Ebook, and Audiobook can inherit and reuse code from the superclass Book. The inheritance hierarchy of the Book superclass can…
-
Sealed Classes and Interfaces 2 – Object-Oriented Programming
A sealed class is declared using the modifier sealed and the optional permits clause in the class header. The permits clause is optional if a sealed class and its permitted direct subclasses are declared in the same compilation unit (p. 317). If a class specifies the permits clause, the class must be declared sealed. The…
-
Private Methods in Interfaces – Object-Oriented Programming
Private Methods in Interfaces Private methods in interfaces are no different from private methods in classes. As such, they can only be accessed inside the interface, acting as helper or auxiliary methods for non-abstract methods declared in the interface. They allow code to be shared between the non-abstract methods in the interface, thus promoting code…
-
Array Store Check – Object-Oriented Programming
Array Store Check An array reference exhibits polymorphic behavior like any other reference, subject to its location in the type hierarchy (p. 278). However, a runtime check is necessary when objects are inserted in an array, as illustrated below. The following assignment is valid, as a supertype reference (Stack[]) can refer to objects of its…
-
Reference Value Assignment Conversions – Object-Oriented Programming
5.9 Reference Value Assignment Conversions In the context of assignments, the following conversions are permitted (Table 2.17, p. 47): In addition, for assignment conversions only, the following conversion is also possible: Note that these rules imply that a widening conversion cannot be followed by any boxing conversion, but the converse is permitted. Widening reference conversions…