Hello all. I'm making my way through 'Head First Java' and have encountered what seems to be a contradiction... Early on (on page 7) the book emphasizes that code structure in Java requires that a source file hold one and only one class definition. Later in the book (pg. 73) there is an example to demonstrate instance variables. I typed the code from pg. 73 into a source file and, just to see what would happen, put both class Dog and class DogTestDrive in the same source file (named DogTestDrive.java) The file compiled and ran successfully. What should I make of this apparent contradiction to the 'one class per source file' rule?? I've included the code below. It compiles successfully when class Dog and class DogTestDrive are in separate files and also when both classes are in the same file <DogTestDrive.java> Thanks in advance for your help.
outer classes are the ones that are not inner classes, inner classes are classes inside a class. You should not worry about this too much at this point, just follow the book and it will show you when appropriate.
charlie crissman wrote:Not sure if that is bad forum protocol to ask another question in an existing thread.
It is bad protocol to ask an unrelated or new question in an existing thread. But threads often lead naturally from one question to another, or a question is refined, as has happened here. Then it is like a conversation leading to more detailed discussion of a topic.