Forum Stats

  • 3,872,599 Users
  • 2,266,457 Discussions
  • 7,911,262 Comments

Discussions

Implementing or Overriding???

843789
843789 Member Posts: 46,655 Green Ribbon
When you extend an abstract class and create the necessary concrete methods, are you implementing or overriding?

Or, are these words interchangeable in this situation?

Thanks for the info!

Comments

  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    From the JLS:

    8.4.8.1 Overriding (by Instance Methods)
    An instance method m1 declared in a class C overrides another instance method, m2, declared in class A iff all of the following are true:

    1. C is a subclass of A.
    2. The signature of m1 is a subsignature (�8.4.2) of the signature of m2.
    3. Either
    * m2 is public, protected or declared with default access in the same package as C, or
    * m1 overrides a method m3, m3 distinct from m1, m3 distinct from m2, such that m3 overrides m2.

    Moreover, if m1 is not abstract, then m1 is said to implement any and all declarations of abstract methods that it overrides.
  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    When you extend an abstract class and create the
    necessary concrete methods, are you
    implementing or overriding?
    I'll try to respond in english for you. First, they are different.

    Implementing (in the context you are speaking of) is when you are required by contract to implement a method declared in an interface class.

    Overriding is when you subclass and implement a method already defined in the parent class, thus overriding it.
  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    I'll try to respond in english for you.
    But the JLS is written in English! And the last sentence in my quote is both clear and contradicts what you wrote!

    "Moreover, if m1 is not abstract, then m1 is said to implement any and all declarations of abstract methods that it overrides."

    So, the answer to the original question is that overrides and implements.
This discussion has been closed.