Re: Simple method declaration question...

From: . (._at_.com)
Date: 02/11/05


Date: Fri, 11 Feb 2005 19:16:58 +0800

Thanks Anthony,

but if 2. is a problem because the return type is different, then why is 3.
OK?

Apparently there is only 1 of the 4 that is bad......

Regards

Michael

"Anthony Borla" <ajborla@bigpond.com> wrote in message
news:GszOd.154591$K7.45715@news-server.bigpond.net.au...
> "." <.@.com> wrote in message
> news:420aaeb4$0$1460$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
>> Hi All,
>>
>> can someone please give me the answer to the following
>> and an explanation of why the declaration is illegal? I am
>> having trouble with this concept....
>>
>> Which of the following methods will be illegal in the
>> subclass?
>>
>
> Version 2. because whilst it matches the base class version in signature,
> the return type is different; the compiler refuses to generate code for
> it.
>
> On the other hand, each of the other method versions may be implemented
> [together or seperately]. However, only the one which matches the base
> class
> version in both:
>
> * Signature [method name, argument number, order, and
> type]
>
> * Return type
>
> will act to override the base class version when used polymorphically
> which
> is, I believe, the behaviour you are expecting. Only version 1. meets this
> criterion.
>
>> import java.io.*;
>>
>> public class A {
>> public double method1(double x, double y) { return 1.0; }
>> }
>>
>> class B extends A {
>> //subclass method to be placed after this line
>> }
>>
>> 1. public double method1(double x, double y) { ... }
>> 2. public int method1(double x, double y) { ... }
>> 3. public int method1(double x, double y, double z) { ... }
>> 4. public double method1(int x, int y) { .... }
>>
>
> The following link may be of use:
>
> http://java.sun.com/docs/books/tutorial/java/javaOO/override.html
>
> I hope this helps.
>
> Anthony Borla
>
>



Relevant Pages

  • Re: Event question
    ... I don't override the event. ... In the base class I declared the abstract method: ... The purpose of this method is to call all assigned delegates - OnMsgSent - ... > Best Regards ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OT: anger-fest thread
    ...  I know he is trolling with regards to ... I see you have changed your tune with regards to outsider - I did ... he picks on Michael and you jump in. ...
    (alt.support.diabetes)
  • Re: Cannot start Cluster Resources
    ... Regards ... "Michael P. Schieferer" wrote: ... >> we have a 2-Node Cluster here wich running Exchange, File and DHCP ...
    (microsoft.public.windows.server.clustering)
  • Re: putty and SuSE and OpenSSH2 without password
    ... >>> regards ... >>> Michael ... > in the putty-help it should only be no write permissions for group/other. ... William Hooper ...
    (comp.security.ssh)
  • Re: Chart with Month-Scale, MajorUnitScale
    ... They are TickMarkUnitType, TickMarkSpacing, ... TickLabelUnitType and TickLabelSpacing! ... Regards ... Michael ...
    (microsoft.public.office.developer.web.components)