“The method main cannot be declared static; static methods can only be declared in a static or top level type”

前端 未结 3 1044
清酒与你
清酒与你 2021-01-14 16:18
class Perkusja {
  boolean talerze = true;
  boolean beben = true;

  void zagrajNaBebnie() {
    System.out.println(\"bam, bam, baaaa-am-am\");
  }
  void zagrajNaT         


        
相关标签:
3条回答
  • 2021-01-14 17:05

    You are declaring your main method in PerkusjaTester which is an inner class of Perkusja. That is forbidden.

    You should declare your test class outside of class Perkusja

    Note : PerkusjaTester is an inner class, not a static nested class. That is why PerkusjaTester is not a static type. As mentionned by Jon Skeet, you could also add the keyword static on class PerkusjaTester.

    0 讨论(0)
  • 2021-01-14 17:07

    The main method in PerkusjaTester is an inner class of Perkusja which is forbidden. Considering you are new to this the simple answer I can give is, remove the last curly bracket and put it above class PerkusjaTester, the error will be removed.

    0 讨论(0)
  • 2021-01-14 17:09

    This code cannot work since, conceptually, an instance of an Perkusja would have to be declared in advance of main being called.

    This is because the inner class PerkusjaTester is not marked as static.

    The best fix for you is to write static class PerkusjaTester {.

    Then main is accessible.

    0 讨论(0)
提交回复
热议问题