Creating custom classes
Now, we could create a new class within the file we're already working in; however, class declaration code is a little different and logically discrete from something like the executed main() method, where the lines are executed one after another in order. Rather, the class we're going to create is going to serve more as a reference for the lines of code, such as the Scanner reader = new Scanner(System.in); code line. Generally, when working in an object-oriented language, a high-level object-oriented language such as Java, we simply put each and every new class we create in its own separate file.
To create a new Java file for our class, just right-click on the package name on the left-hand side of the screen, that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access