6 Replies Latest reply: Jul 23, 2007 6:46 AM by 807605 RSS

    java inheritance

    807605
      hello,

      i'm trying to use a super class called A and a derived class called B.
      class A has a method that gets a parameter of type C which is also a super class. class D inherites class C. The code:

      class A{
      public void foo(C c){...}
      }

      Class B{
      public void foo(D d){...}
      }

      it gives me a compilation error, how can i make this work?
      thanks!!
        • 1. Re: java inheritance
          800322
          Lowercase 'c' in class.... What error do you get?
          • 2. Re: java inheritance
            807605
            this was just a typo...

            i'm getting:

            The method foo(D) in the type B is not applicable for the arguments (C)

            thanks
            • 3. Re: java inheritance
              800322
              So somewhere you're calling that method with a C as a parameter. And your B does not extend A so it doesn't inherit the other method.
              • 4. Re: java inheritance
                807605
                ok, i made some errors in my first questions, sorry for that:

                class A{
                public void foo(C c){...}
                }

                class B extends A{
                public void foo(D d){...}
                }

                and as i said D extends C and the error:
                The method foo(D) in the type B is not applicable for the arguments (C)
                is a compilation error.

                thanks again!!
                • 5. Re: java inheritance
                  807605
                  Iam not sure But I believe You cant redefine a methods signature as you did.
                  Of course method redefinition is always acceptable.
                  • 6. Re: java inheritance
                    807605
                    > The method foo(D) in the type B is not applicable for
                    the arguments (C) is a compilation error.

                    The code you posted compiles just fine. The problem is elsewhere. Time for you to post an SSCCE* that actually demonstrates the compiler error.

                    *http://mindprod.com/jgloss/sscce.html

                    > i'm trying to use a super class called A and a derived class called B.

                    Hopefully, you're using more meaningful names than that. And if you are, you should use those names in the sample code you post here (or at least something meaningful).

                    ~