Java Reference
In-Depth Information
< Day Day Up >
A Glossary of Name Reuse
Most of the puzzles in this chapter were based on name reuse. This section summarizes the various
forms of name reuse.
Overriding
An instance method overrides all accessible instance methods with the same signature in
superclasses [JLS 8.4.8.1], enabling dynamic dispatch; in other words, the VM chooses which
overriding to invoke based on an instance's run-time type [JLS 15.12.4.4]. Overriding is
fundamental to object-oriented programming and is the only form of name reuse that is not
generally discouraged:
class Base {
public void f() { }
}
class Derived extends Base {
public void f() { } // overrrides Base.f()
}
Hiding
A field, static method, or member type hides all accessible fields, static methods, or member types,
respectively, with the same name (or, for methods, signature) in supertypes. Hiding a member
prevents it from being inherited [JLS 8.3, 8.4.8.2, 8.5]:
class Base {
public static void f() { }
}
 
 
Search WWH ::




Custom Search