Types All interfaces and classes are types. All variabes in Java must have a type.
The type of a variable determines what methods are visible. This is the visibility principle.
When a method call is communicated via a variable, the "pointee" is responsible for executing the method. This is the delegation principle, so-called because the job of executing the code is delegated to the pointee.
Types in Java are organized into a hierarchy.
All classes automatically inherit from the root
class
java.lang.Object
.
This is why any class you create automaticaly has
the methods toString()
and equals
.
final
AgainThe final
keyword can appear in two
contexts in inheritance.
final
, it cannot
be extended. The class String
and the
wrapper classes are all final classes.final
,
it cannot be overrriden by a descendant classBoth of these stipuations are enforced at compile time. This article supplies a security rationale for making the String class final.