Just started learning Java. Why is the main() inside of a class?

后端 未结 3 395
灰色年华
灰色年华 2021-01-14 09:17

I\'m learning Java and I noticed that the main() is put inside of a class. Why? I don\'t consider my main() to be a member of any object. So please

3条回答
  •  孤街浪徒
    2021-01-14 09:56

    I don't consider my main() to be a member of any object.

    It's not since it's a static method. It does not belong to any object but to the class itself.

    Aside from that, all methods, including main must be defined in classes.

    More generally, a class is the smallest unit in compiled Java code and contains both information on instances of the class and behavioral code that runs by itself (e.g. the main method).

提交回复
热议问题