It's because when the command issued was
java ... Cartoon.java, this caused Java to go into "source-file mode".
From the documentation (
https://docs.oracle.com/en/java/javase/11/tools/java.html):
In source-file mode, the effect is as though the source file is compiled into memory, and the first class found in the source file is executed. Any arguments placed after the name of the source file in the original command line are passed to the compiled class when it is executed.
If the Cartoon class declaration had been at the top instead of at the bottom, it would have run fine. Of course, since you didn't know about source-file mode, then you would have been under the wrong impression that what you did was fine. If you moved the
Drawing class to the top of the file and ran the same command, it would have complained about the Drawing class instead.