More Practice

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

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

More Practice

Non-abstract children must override the abstract methods of their parents. Here is our situation:

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

class Child extends Parent
{
      // child's compute method
}

Examine each of the following choices for filling the blank. What will the new definition do? Override the parent's method, define an additional method, or be an error? (If the choice defines an additional method, assume that the required method is also defined.)

method defined in ChildOverride, Additional, or Error?
public int compute( int x, String j ){ . . . }
public int compute( int stuff, String str ){ . . . }
public int Compute( int x, String j ){ . . . }
public int compute( String j, int x){ . . . }
public double compute( int x, String j){ . . . }

QUESTION 4:

Say that a child class defines just one method, and that method has the same name as the parent's abstract method, but with a different signature. Must the child class be abstract?