13.4.23
Method Overriding
BINARY COMPATIBILITY
class Super {
static void out(float f) { System.out.println("float"); }
static void out(int i) { System.out.println("int"); }
}
If
Super
 is recompiled but not
Test
, then running the new binary with the exist 
ing binary of
Test
 still produces the output:
float
However, if
Test
 is then recompiled, using this new
Super
, the output is then:
int
as might have been naively expected in the previous case.
13.4.23   Method Overriding
If an instance method is added to a subclass and it overrides a method in a super 
class, then the subclass method will be found by method invocations in pre exist 
ing binaries, and these binaries are not impacted. If a class method is added to a
class, then this method will not be found, because the invocation of a class method
is resolved at compile time to use the fully qualified name of the class where the
method is declared. Thus if the example:
class Hyper {
void hello() { System.out.print("Hello, "); }
static void world() { System.out.println("world!"); }
}
class Super extends Hyper { }
class Test {
public static void main(String[] args) {
Super s = new Super();
s.hello();
s.world();
}
}
is compiled and executed, it produces the output:
Hello, world!
Suppose that a new version of class
Super
 is produced:
class Super extends Hyper {
void hello() { System.out.print("Goodbye, cruel "); }
static void world() { System.out.println("earth!"); }
}
258






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved