Java Reference
In-Depth Information
class Derived extends Base {
public static void f() { } // hides Base.f()
}
Overloading
Methods in a class overload one another if they have the same name and different signatures. The
overloaded method designated by an invocation is selected at compile time [JLS 8.4.9, 15.12.2]:
class CircuitBreaker {
public void f(int i) { } // int overloading
public void f(String s) { } // String overloading
}
Shadowing
A variable, method, or type shadows all variables, methods, or types, respectively, with the same
name in a textually enclosing scope. If an entity is shadowed, you cannot refer to it by its simple
name; depending on the entity, you cannot refer to it at all [JLS 6.3.1]:
class WhoKnows {
static String sentence = "I don't know.";
public static void main(String[] args) {
String sentence = "I know!"; // shadows static field
System.out.println(sentence); // prints local variable
}
}
 
 
Search WWH ::




Custom Search