简体   繁体   中英

Abstract Class and Concrete Subclasses

I have two files: Validador.java and Peca.java . This is what I have in my Validador:

public class Validador {
    public static void main(String[] args) {
        if(args.length == 0) { 

             Peca p = new Rainha("t",1,2);

        }else if (args[0].equals("filtro")) { 

        }
    }
}

Peca:

public abstract class Peca {
    public static class Rainha extends Peca {
        Rainha(Tabuleiro tab, int linha, int coluna) {

        }
    }
    public static class Nada extends Peca {
        Nada(Tabuleiro tab, int linha, int coluna) {

        }
    }

}

I am getting this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
        Rainha cannot be resolved to a type

        at Validador.main(Validador.java:5)

How can I fix my Peca in order to be possible to call Rainha like this?

Peca p = new Rainha("t",1,2);

Thanks

You must either import Peca.Rainha or write Peca p = new Peca.Rainha("t",1,2);

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