Category: Oracle Certification Exam
-
Method Invocation Conversions Involving References – Object-Oriented Programming
5.10 Method Invocation Conversions Involving References The conversions for reference value assignment are also applicable to method invocation conversions, except for the narrowing conversion for constant expressions of non-long integer type (Table 2.17, p. 47). This is reasonable, as parameters in Java are passed by value (§3.10, p. 127), requiring that values of the actual…
-
Overloaded Method Resolution – Object-Oriented Programming
Overloaded Method Resolution In this subsection, we take a look at some aspects regarding overloaded method resolution—that is, how the compiler determines which overloaded method will be invoked by a given method call at runtime. Resolution of overloaded methods selects the most specific method for execution. One method is considered more specific than another method…
-
Arrays and Subtyping – Object-Oriented Programming
5.7 Arrays and Subtyping Table 5.4 summarizes the types found in Java. Only primitive data and reference values can be stored in variables. Only class and array types can be explicitly instantiated to create objects. Table 5.4 Types and Values Types Values Primitive data types Primitive data values Class, interface, enum, and array types (reference…
-
Reference Casting and the instanceof Operator – Object-Oriented Programming
5.11 Reference Casting and the instanceof Operator In this section we explore type casting of references and the instanceof operator that can be used to perform either type comparison or pattern matching. The Cast Operator The basic form of the type cast expression for reference types has the following syntax: Click here to view code…
-
The instanceof Type Comparison Operator – Object-Oriented Programming
The instanceof Type Comparison Operator The binary instanceof operator can be used for comparing types. It has the following syntax when used as a type comparison operator (note that the keyword is composed of lowercase letters only): Click here to view code image reference_expression instanceofdestination_type The instanceof type comparison operator returns true if the left-hand operand…
-
The instanceof Type Comparison Operator 2 – Object-Oriented Programming
As we have seen, the instanceof type comparison operator effectively determines whether the reference value in the reference on the left-hand side refers to an object whose class is a subtype of the type specified on the right-hand side. At runtime, it is the type of the actual object denoted by the reference on the…
-
The instanceof Pattern Match Operator – Object-Oriented Programming
The instanceof Pattern Match Operator The instanceof operator can also be used for pattern matching, as explained below. It has the following syntax when used as a pattern match operator: Note that the syntax of the instanceof pattern match operator augments the syntax of the instanceof type comparison operator with a pattern variable. The type…
-
Scope of Pattern Variables – Object-Oriented Programming
Scope of Pattern Variables We first examine the scope of a pattern variable in an if-else statement. If the instanceof pattern match operator returns true in the conditional of an if statement, the pattern variable is introduced and its scope is the if block. Not surprisingly, this is also the case for the if-else statement.…
-
Declaring Enum Constructors and Members – Object-Oriented Programming
Declaring Enum Constructors and Members An enum type can declare constructors and other members as in an ordinary class, but the enum constants must be declared before any other declarations (see the declaration of the enum type Meal in Example 5.25). The list of enum constants must be terminated by a semicolon (;) if followed…
-
Polymorphism 2 – Object-Oriented Programming
In the for(:) loop at (3) in Example 5.23, depending on the type of the object denoted by the loop variable drawable, the call to the draw() method will result in the draw() method of this object to be executed. The instanceof type comparison operator returns true if the reference specified as its left-hand operand…