go to previous page   go to home page   go to next page

Answer:

Yes.


Overriding abstract Methods

An abstract class usually contains abstract methods. (Although if a class is declared to be abstract, then it is, even if it has no abstract methods.) An abstract method definition consists of:

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);
}

Here is a child of Parent:

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

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

If a class has one or more abstract methods it must be declared to be abstract. An abstract class may have methods that are not abstract (the usual sort of method). These methods are inherited by child classes in the usual way. A non-abstract child class of an abstract parent class must override each of the abstract methods of its parent.

These rules are not really as terrible as they seem. After working with inheritance for a while the rules will be clear.


QUESTION 3:

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

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

go to previous page   go to home page   go to next page