title: how to extend a abstract class in java
body: <p>I have a made an engine class that is as follows. based on </p>
  
  <p>Engine: Interface   that    extends Java’s  Comparable  (to compare among   engines)    and declares    an  integer 
  getter  method  “getForce”, which   indicatesthat   engine subclasses will  have    a   force they  are capable of<br>
  producing.</p>
  
  <pre><code>public interface Engine extends Comparable&lt;Engine&gt;{
  
  public int getForce();
  
  }
  </code></pre>
  
  <p>I am trying to make an <code>AbstractEngine</code> class based on the following description. </p>
  
  <p><code>AbstractEngine</code>: Abstract class implemented by most engines.  It subclasses from Engine and has an integer field indicating its force.  This field is initialized through a constructor. The class overrides <code>getForce</code> from <code>Engine</code> and <code>compareTo</code> from <code>Comparable</code>. The comparison of two engines is done by finding the difference between their forces (in such a way that sorting a collection of engines arranges. I am confused on overriding the methods from <code>Engine</code> and making sure <code>AbstractEngine</code> has the compare to the <code>Engine</code> has. </p>
  
  <p>This is what I have at the moment, but it's failing a JUnit test checking if <code>AbstractEngine</code> has the <code>getForce</code>, <code>equals</code>, and <code>CompareTo</code>. Is there a specific way I have to extend the methods?</p>
  
  <pre><code>abstract class AbstractEngine implements Engine {
  
  public AbstractEngine(int force){
  
  }
  public int compareTo(Engine o) {
      // TODO Auto-generated method stub
      return 0;
  }
  }
  </code></pre>
  
  <p>here is the junit test</p>
  
  <pre><code>import static org.junit.Assert.*;
  
  import org.junit.Test;
  
  public class EngineTest {
  
  @Test
  public void test0_EngineImplementsComparableAndDefinesGetForce() {
      Engine engine = new Engine() {
          @Override
          public int compareTo(Engine o) {
              return 0;
          }
          @Override
          public int getForce() {
              return 0;
          }
      };
      assertTrue( "Incorrect result", engine instanceof Comparable );
  }
  @Test
  public void test1_AbstractEngineIsAnEngine() {
      Engine engine = new AbstractEngine( 2 ) { };
      assertTrue( "Incorrect result", engine instanceof Engine );
  }
  @Test
  public void test2_AbstractEngineHasGetForce() {
      Engine engine   = new AbstractEngine( 24 ) { };
      int    actual   = engine.getForce();
      int    expected = 24;
      assertEquals( "Incorrect result", expected, actual );
  }
  @Test
  public void test3_AbstractEngineHasEquals() {
      Engine  a, b;
      boolean actual;
      // equal to itself
      a      = new AbstractEngine( 42 ) { };
      actual = a.equals( a );
      assertTrue ( "Incorrect result", actual );
      // equal to another engine with the same force
      a      = new AbstractEngine( 19 ) { };
      b      = new AbstractEngine( 19 ) { };
      actual = a.equals( b );
      assertTrue ( "Incorrect result", actual );
      // not equal to another engine with a different force 
      a      = new AbstractEngine( 22 ) { };
      b      = new AbstractEngine( 24 ) { };
      actual = a.equals( b );
      assertFalse( "Incorrect result", actual );
      // not equal to null
      actual = a.equals( null );
      assertFalse( "Incorrect result", actual );
      // not equal to some other object
      actual = a.equals( "22" );
      assertFalse( "Incorrect result", actual );
      // not equal to some other object
      actual = a.equals(  22  );
      assertFalse( "Incorrect result", actual );
  }
  @Test
  public void test3_AbstractEngineHasCompareTo() {
      Engine a, b;
      int    actual;
      // equal to itself
      a      = new AbstractEngine( 42 ) { };
      actual = a.compareTo( a );
      assertTrue( "Incorrect result", actual == 0 );
      // equal to another engine with the same force
      a      = new AbstractEngine( 9000 ) { };
      b      = new AbstractEngine( 9000 ) { };
      actual = a.compareTo( b );
      assertTrue( "Incorrect result", actual == 0 );
      // goes before a more powerful engine 
      a      = new AbstractEngine( 23 ) { };
      b      = new AbstractEngine( 24 ) { };
      actual = a.compareTo( b );
      assertTrue( "Incorrect result", actual &lt; 0 );
      // goes after a less powerful engine 
      actual = b.compareTo( a );
      assertTrue( "Incorrect result", actual &gt; 0 );
  }
  @Test
  public void test4_OxIsAnEngine() {
      Ox ox = new Ox( 3 );
      assertTrue( "Incorrect result", ox instanceof AbstractEngine );
  }
  @Test
  public void test5_OxHasGetForce() {
      Engine engine   = new Ox( 4 );
      int    actual   = engine.getForce();
      int    expected = 4;
      assertEquals( "Incorrect result", expected, actual );
  }
  @Test
  public void test5_OxHasEquals() {
      Engine  a, b;
      boolean actual;
      // equal to itself
      a      = new Ox( 42 );
      actual = a.equals( a );
      assertTrue ( "Incorrect result", actual );
      // equal to another engine with the same force
      a      = new Ox( 19 );
      b      = new Ox( 19 );
      actual = a.equals( b );
      assertTrue ( "Incorrect result", actual );
      // not equal to another engine with a different force 
      a      = new Ox( 22 );
      b      = new Ox( 24 );
      actual = a.equals( b );
      assertFalse( "Incorrect result", actual );
      // not equal to another engine of equal force 
      a      = new Ox            ( 21 );
      b      = new AbstractEngine( 21 ) { };
      actual = a.equals( b );
      assertFalse( "Incorrect result", actual );
      // not equal to null
      actual = a.equals( null );
      assertFalse( "Incorrect result", actual );
      // not equal to some other object
      actual = a.equals( "blah" );
      assertFalse( "Incorrect result", actual );
      // not equal to some other object
      actual = a.equals(  111  );
      assertFalse( "Incorrect result", actual );
  }
  }
  </code></pre>