3 Replies Latest reply: Sep 24, 2006 12:46 PM by 796440 RSS

    Extending a superclass

    807569
      I have a class A. I would now like to make another class B that extends A.

      The only difference between A and B is that B should implement an interface that A does not implement.

      I don't want the superclass A to implement this interface it should only be implemented by the child B.

      But it seems rather silly to make a class that only contains "B extends A implements C".
        • 1. Re: Extending a superclass
          796254
          I have a class A. I would now like to make another
          class B that extends A.

          The only difference between A and B is that B should
          implement an interface that A does not implement.

          I don't want the superclass A to implement this
          interface it should only be implemented by the child
          B.

          But it seems rather silly to make a class that only
          contains "B extends A implements C".
          Why is that silly, if that's what you want?

          %
          • 2. Re: Extending a superclass
            807569
            The problem is that my super class A has an add method which does not throw any exception.

            My subclass implements a remote interface where the same method throws a remote exception. I cannot override the superclass method a throw from the add method in class B.
            • 3. Re: Extending a superclass
              796440
              The problem is that my super class A has an add
              method which does not throw any exception.

              My subclass implements a remote interface where the
              same method throws a remote exception.
              If the add method has the same semantics, then you can do it by having the subclass' add method not throw the exception. However, even with the same semantics, to methods with the same signature from two different parent types sounds like a recipe for confusion. And of course, if the two methods have different semantics, then you simply can't do it.

              My advice is to change the name of one of the add methods. If you can't do that, then you'll have to find another approach.