Search code examples
javapolymorphismabstract-classabstractabstraction

difference between code polymorphism examples


package practice;

public abstract class OutterClass {

    public int getMaxRows() {
    }

    public abstract boolean gameOver();
}

public class InnerClass extends OutterClass{

    @Override
    public boolean gameOver() {

        //int lastRow = getMaxRows() - 1;
        //int lastRow = this.getMaxRows() - 1;
        //int lastRow = ((OutterClass)this).getMaxRows() - 1;
        //int lastRow = ((InnerClass)this).getMaxRows() - 1;
        //int lastRow = InnerClass.this.getMaxRows() - 1;

    }

What is the difference between all of the commented out code in the sublass (InnerClass)?


Solution

  • // int lastRow = getMaxRows() - 1;
    // int lastRow = this.getMaxRows() - 1;
    // int lastRow = ((OutterClass)this).getMaxRows() - 1;
    // int lastRow = ((InnerClass)this).getMaxRows() - 1;
    

    These are all identical in effect. The last is especially pointless.

    // int lastRow = InnerClass.this.getMaxRows() - 1;
    

    This won't compile.

    NB Contrary to your nomenclature, there are no inner classes here.