|
|
|
|
|
|
|
|
An interface is an “ultimate” abstract class; |
|
no implementations are allowed. |
|
A class may extend only one other base class,
but may implement multiple interfaces (thus avoiding conflicting multiple
inheritances). |
|
All methods specified in the interface must be
implemented. |
|
If not, it must be declared “abstract”. |
|
All interfaces & their implementations are
“public”. |
|
Interfaces can extend other interfaces. |
|
|
|
|
|
If the implementation is identical except for
the basic type, then Object type is used to get generic implementations. |
|
This is the equivalent of “template” in C++;
every reference type is compatible with the Object type. |
|
When specific methods of the object are needed,
then we need to“downcast” to the correct type. |
|
If a class does not extend another class, it
extends the class Object. It is class (not abstract) with several methods
including toString(). |
|
|
|
If a method required is not available in Object,
then generic implementations can be achieved using interface. |
|
|
|
|
|
|
A functor is an object with no data and a single
method. |
|
Functors can be passed as parameters. |
|
Since these classes are very “small”, they are
usually implemented as a Nested Class wherever they are needed. |
|
Nested classes are defined inside other classes
and it is essential that it be declared as “static”. If it is not declared
as “static”, then it is an “inner” class (not nested). |
|
Nested classes act as members of the “outer”
class, and can be declared as private, public, protected, or package
visible. |
|
A nested class can access private fields and
members of the “outer” class. |
|
Functors can be implemented as a Local Class or
as an Anonymous Class. |
|
|
|
|
|
|
|
|
In a derived class, if a method declaration does
not match the exact signature, then it is not an “override”, but an
“overload”. |
|
If a method is declared as final, it cannot be
overridden. |
|
If a
class is declared as final, it cannot be extended. |
|
|