Please tell me the main method doesn't have to be inside a class?

  • four
    it is java, everything must be a member of at least some class in it. Or are you asking if each class should have a public static void main(String[] args) method? no, not necessarily. - zRrr

1 answer 1

Must, this condition can not be violated. No matter what class, at least one main() function should be.

  • And if I have for example a parent (main) class and a successor, can I write the main method only in the parent class in this case? - Muscled Boy
  • 3
    @MuscledBoy in any. - Nofate
  • and why? Explain, please? - Muscled Boy
  • one
    @MuscledBoy because the creators of the language so decided, making the maximum object-oriented. - D-side
  • thanks for your reply - Muscled Boy