Re: Simple method declaration question...
From: . (._at_.com)
Date: 02/11/05
- Next message: MS: "Re: [unchecked] unchecked call to add(E) --using ArrayList."
- Previous message: Chris Uppal: "Re: How do I view code generated by a Just-In-Time Compiler?"
- In reply to: Anthony Borla: "Re: Simple method declaration question..."
- Next in thread: Tor Iver Wilhelmsen: "Re: Simple method declaration question..."
- Reply: Tor Iver Wilhelmsen: "Re: Simple method declaration question..."
- Reply: sanjay manohar: "Re: Simple method declaration question..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
>
>
- Next message: MS: "Re: [unchecked] unchecked call to add(E) --using ArrayList."
- Previous message: Chris Uppal: "Re: How do I view code generated by a Just-In-Time Compiler?"
- In reply to: Anthony Borla: "Re: Simple method declaration question..."
- Next in thread: Tor Iver Wilhelmsen: "Re: Simple method declaration question..."
- Reply: Tor Iver Wilhelmsen: "Re: Simple method declaration question..."
- Reply: sanjay manohar: "Re: Simple method declaration question..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|