CS 310, Object-Oriented Programming with Java

Quiz 8, 20 March 2008


  1. Explain whether or not the @Override annotation is doing anything useful in the following code excerpt:

    interface Fun {
      public void f(int x);
      }
    
    //blah blah blah
    
    void moo() {
      Fun f = new Fun() {
        @Override public void f(int x) {
          // blah blah blah
          }
        }
    
      // blah blah blah
      }
    


    Not really. The @Override annotation helps catch cases where a child has misdeclarations when overriding ancestor methods (page 173 (7th ed.) or 196 (8th ed.)). However, an interface is implicitly abstract, as are all methods defined in the interface (page 212 (7th ed.) or 243 (8th ed.)). An abstract class cannot be instantiated (page EdPage(165, 188)), and a misdeclaration without an @Override annotation would still result in a compilation-time error, although of a different kind.

  2. Reproduce the 2x2 matrix showing the relation between the most abstract classes in Java's I-O hierarchy. Your reproduction should be accurate, but need not be precise.


    the 2x2 matrix o' abstract I-O classes


This page last modified on 31 March 2008.