On 2 May 2004 10:23:28 GMT, Joona I Palaste <>
wrote or quoted :
>Vehicle v;
>if (someRunTimeFlag) {
> v = new Vehicle();
>}
>else {
> v = new Ferrari();
>}
>v.getSpeed();
>Now is the compiler supposed to somehow see into the future and
>predict whether someRunTimeFlag will be true or not?
Since Ferrari is derived from Vehicle, the compiler only assumes that
v is a Vehicle and Ferrari is a type of Vehicle. IT will use look at
a table AT RUN TIME to find the getSpeed method for Ferraris, with may
be the same as for generic vehicles or it may be overridden.
See
http://mindprod.com/jgloss/gotchas.html
and search for recipe to get a handle on how this overriding business
works.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See
http://mindprod.com/jgloss/jgloss.html for The Java Glossary.