A good answer might be:

Yes.

Overriding abstract Methods

An abstract class will usually contain abstract methods. An abstract method definition consists of:

  • optional access modifier (public, private, and others),
  • the reserved word abstract,
  • the class of the return value,
  • a method signature,
  • a semi-colon.
No curly braces or method body follow the signature. Here is the abstract class Parent including the abstract compute() method:

abstract class Parent
{
  public abstract int compute( int x, String j);
}

An abstract class may have methods that are not abstract (the usual sort of method) and that are inherited by its child classes in the usual way. But if there is one or more abstract method, the parent must be declared to be abstract. A non-abstract child class of an abstract parent class must override each of the abstract methods of its parent.

  • A child must override an abstract method inherited from its parent by defining a method with the same signature and same return type.
    • Child objects now will include this method.

  • A child may define an additional method method with a different signature from the parent's method.
    • Child objects now will include two methods---the required one from the parent and the additional method.

  • It is an error if a child defines a method with the same signature as a parent method, but with a different return type.

These rules are not really as terrible as they seem. After working with inheritance for a while the rules will seem obvious. Here is a child of Parent:

class Child extends Parent
{
    public int compute( int x, String j )
    { . . . }                                   // method body
}

The child's compute() method correctly overrides the parent's abstract method.

QUESTION 3:

Would the following correctly override the parent's abstract method?

class Child extends Parent
{
    public double compute( int x, String j )
    { . . . }                                   // method body
}

Click Here after you have answered the question