> i have a method in class A named
> protected int foo(int args) { /* ..... */ }
> and have a class B that extends class A and would like to have a
> method foo in it which overrides it as
> public double foo(int args) { /*........*/}
This is not allowed in Java. And if it were allowed, the return type of the
overriding method (double in your case) should be 'more specific' then the
return type of the overriden method (int in your case). After all a subclass
should obey the contract of its superclass. So if the return type of the
overriden method is double, it would be legal (from a object-oriënted
programming point-of-view) to override it with a method returning a int
(since each int can be implicitly casted to a double). But again: none of
this is possible in Java.
sks - 15 Nov 2005 13:21 GMT
>> i have a method in class A named
>> protected int foo(int args) { /* ..... */ }
[quoted text clipped - 10 lines]
> returning a int (since each int can be implicitly casted to a double). But
> again: none of this is possible in Java.
You can do that with Object types (not primitives) in 1.5
Roedy Green - 15 Nov 2005 18:35 GMT
>You can do that with Object types (not primitives) in 1.5
and the overriding type has to be more specific, e.g. base returns
Dog, override always returns Dalmatian, not the reverse. Dalmatian
is still a Dog.
You can't break the contract of the original base class.
.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.