简体   繁体   中英

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)?

// 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM