EXPRESSIONS
Runtime Evaluation of Method Invocation
15.11.4
color = 0;
}
}
the subclass
ColoredPoint
 extends the
clear
 abstraction defined by its super 
class
Point
. It does so by overriding the
clear
 method with its own method,
which invokes the
clear
 method of its superclass, using the form
super.clear
.
This method is then invoked whenever the target object for an invocation of
clear
 is a
ColoredPoint
. Even the method
move
 in
Point
 invokes the
clear
method of class
ColoredPoint
 when the class of
this
 is
ColoredPoint
, as
shown by the output of this test program:
class Test {
public static void main(String[] args) {
Point p = new Point();
System.out.println("p.move(20,20):");
p.move(20, 20);
ColoredPoint cp = new ColoredPoint();
System.out.println("cp.move(20,20):");
cp.move(20, 20);
p = new ColoredPoint();
System.out.println("p.move(20,20), p colored:");
p.move(20, 20);
}
}
which is:
p.move(20,20):
Point clear
cp.move(20,20):
ColoredPoint clear
Point clear
p.move(20,20), p colored:
ColoredPoint clear
Point clear
Overriding is sometimes called  late bound self reference ; in this example it
means that the reference to
clear
 in the body of
Point.move
 (which is really
syntactic shorthand for
this.clear
) invokes a method chosen  late  (at run time,
based on the run time class of the object referenced by
this
) rather than a method
chosen  early  (at compile time, based only on the type of
this
). This provides
the Java programmer a powerful way of extending abstractions and is a key idea in
object oriented programming.
339






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