There is a task: to create a class and its successor. Should classes be created in a single java file or should each be in its own file with a .java ?
|
1 answer
In your case, it is better to create both classes in one file, but it is always better to create each class in a separate file.
- and create a project with the main class of "man"? and explain, please, why they are usually created in different files - Muscled Boy
- oneAs a rule, the main class
Mainwith an entry pointpublic static void main(String[] args)- Alexey Shimansky - that is, the classes “person”, “student”, “main” (there will be no fields and methods other than the main one, and there are “basic actions” in it — creating instances of the classes “person” and “student”, for example)? do I understand you correctly? - Muscled Boy
- one
main()is the main method. This is the line from which the program starts. Point of entry. AllJavaapplications should have onemain()method. ...... A class that does not have a main method can be successfully compiled, but cannot be executed, because it does not have a starting point of execution, which is themain()method - Alexey Shimansky - one@MuscledBoy The class with the entry point
main()can be named as you like, even though theclass RahamBaharamamBuru. The main thing that was the main class with the entry point. Simply, this main class is often called theMain(with a capital letter) ..... catches the eye and immediately intuitively understands what kind of class it is - Alexey Shimansky
|
publicname of the top-level class must match the name of the file, so there will be only one such class in the file. This is the only real limitation. Small tasks, so as not to produce projects and not litter the namespace in one project, you can create a separate sub-package for each lesson, or use nested static classes in a class withmain. - zRrr